# Path: deluge/component.py
# class ComponentAlreadyRegistered(Exception):
# class Component(object):
# class ComponentRegistry(object):
#     def __init__(self, name, interval=1, depend=None):
#     def _component_start_timer(self):
#     def _component_start(self):
#         def on_start(result):
#         def on_start_fail(result):
#     def _component_stop(self):
#         def on_stop(result):
#     def _component_pause(self):
#         def on_pause(result):
#     def _component_resume(self):
#         def on_resume(result):
#     def _component_shutdown(self):
#         def on_stop(result):
#     def __init__(self):
#     def register(self, obj):
#     def deregister(self, name):
#             def on_stop(result, name):
#     def start(self, names=[]):
#         def on_depends_started(result, name):
#     def stop(self, names=[]):
#     def pause(self, names=[]):
#     def resume(self, names=[]):
#     def shutdown(self):
#     def update(self):
# def get(name):
# 
# Path: deluge/ui/web/json_api.py
# class JSONComponent(component.Component):
#     def __init__(self, name, interval=1, depend=None):
#         super(JSONComponent, self).__init__(name, interval, depend)
#         self._json = component.get("JSON")
#         self._json.register_object(self, name)
# 
# def export(auth_level=AUTH_LEVEL_DEFAULT):
#     """
#     Decorator function to register an object's method as a RPC. The object
#     will need to be registered with a `:class:JSON` to be effective.
# 
#     :param func: the function to export
#     :type func: function
#     :keyword auth_level: the auth level required to call this method
#     :type auth_level: int
# 
#     """
#     global AUTH_LEVEL_DEFAULT, AuthError
#     if AUTH_LEVEL_DEFAULT is None:
#         from deluge.ui.web.auth import AUTH_LEVEL_DEFAULT, AuthError
# 
#     def wrap(func, *args, **kwargs):
#         func._json_export = True
#         func._json_auth_level = auth_level
#         return func
# 
#     if type(auth_level) is FunctionType:
#         func = auth_level
#         auth_level = AUTH_LEVEL_DEFAULT
#         return wrap(func)
#     else:
#         return wrap
# 
# Path: deluge/ui/web/auth_config.py
# AUTH_LEVEL_NONE = 0
# AUTH_LEVEL_READONLY = 1
# AUTH_LEVEL_NORMAL = 5
# AUTH_LEVEL_ADMIN = 10


import time
import random
import hashlib
import logging
from datetime import datetime, timedelta
from email.utils import formatdate
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
from deluge import component
from deluge.ui.web.json_api import JSONComponent, export
from deluge.ui.web.auth_config import remote_methods_access
            from base64 import decodestring
        :param new_password: the password to change to
        :type new_password: string
        """
        if not self.check_password(old_password):
            return False
        return self._change_password(new_password)
    
    @export(AUTH_LEVEL_NONE)
    def check_session(self, session_id=None):
        """
        Check a session to see if it's still valid.
        
        :returns: True if the session is valid, False if not.
        :rtype: booleon
        """
        return __request__.session_id is not None
    
    @export
    def delete_session(self):
        """
        Removes a session.
        
        :param session_id: the id for the session to remove
        :type session_id: string
        """
        d = Deferred()
        config = component.get("DelugeWeb").config
        del config["sessions"][__request__.session_id]
        return True
    

# Path: deluge/component.py
# class ComponentAlreadyRegistered(Exception):
# class Component(object):
# class ComponentRegistry(object):
#     def __init__(self, name, interval=1, depend=None):
#     def _component_start_timer(self):
#     def _component_start(self):
#         def on_start(result):
#         def on_start_fail(result):
#     def _component_stop(self):
#         def on_stop(result):
#     def _component_pause(self):
#         def on_pause(result):
#     def _component_resume(self):
#         def on_resume(result):
#     def _component_shutdown(self):
#         def on_stop(result):
#     def __init__(self):
#     def register(self, obj):
#     def deregister(self, name):
#             def on_stop(result, name):
#     def start(self, names=[]):
#         def on_depends_started(result, name):
#     def stop(self, names=[]):
#     def pause(self, names=[]):
#     def resume(self, names=[]):
#     def shutdown(self):
#     def update(self):
# def get(name):
# 
# Path: deluge/ui/web/json_api.py
# class JSONComponent(component.Component):
#     def __init__(self, name, interval=1, depend=None):
#         super(JSONComponent, self).__init__(name, interval, depend)
#         self._json = component.get("JSON")
#         self._json.register_object(self, name)
# 
# def export(auth_level=AUTH_LEVEL_DEFAULT):
#     """
#     Decorator function to register an object's method as a RPC. The object
#     will need to be registered with a `:class:JSON` to be effective.
# 
#     :param func: the function to export
#     :type func: function
#     :keyword auth_level: the auth level required to call this method
#     :type auth_level: int
# 
#     """
#     global AUTH_LEVEL_DEFAULT, AuthError
#     if AUTH_LEVEL_DEFAULT is None:
#         from deluge.ui.web.auth import AUTH_LEVEL_DEFAULT, AuthError
# 
#     def wrap(func, *args, **kwargs):
#         func._json_export = True
#         func._json_auth_level = auth_level
#         return func
# 
#     if type(auth_level) is FunctionType:
#         func = auth_level
#         auth_level = AUTH_LEVEL_DEFAULT
#         return wrap(func)
#     else:
#         return wrap
# 
# Path: deluge/ui/web/auth_config.py
# AUTH_LEVEL_NONE = 0
# AUTH_LEVEL_READONLY = 1
# AUTH_LEVEL_NORMAL = 5
# AUTH_LEVEL_ADMIN = 10


# Path: deluge/ui/web/auth.py
import time
import random
import hashlib
import logging
from datetime import datetime, timedelta
from email.utils import formatdate
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
from deluge import component
from deluge.ui.web.json_api import JSONComponent, export
from deluge.ui.web.auth_config import remote_methods_access
            from base64 import decodestring

        :param new_password: the password to change to
        :type new_password: string
        """
        if not self.check_password(old_password):
            return False
        return self._change_password(new_password)
    
    @export(AUTH_LEVEL_NONE)
    def check_session(self, session_id=None):
        """
        Check a session to see if it's still valid.
        
        :returns: True if the session is valid, False if not.
        :rtype: booleon
        """
        return __request__.session_id is not None
    
    @export
    def delete_session(self):
        """
        Removes a session.
        
        :param session_id: the id for the session to remove
        :type session_id: string
        """
        d = Deferred()
        config = component.get("DelugeWeb").config
        del config["sessions"][__request__.session_id]
        return True
    

    @export(AUTH_LEVEL_NONE)