diff --git a/__init__.py b/__init__.py index 7421084..bdfa34d 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1,3 @@ -from .forgot_password import * +from .forgot_password import init + +init() diff --git a/forgot_password/__init__.py b/forgot_password/__init__.py index 9c6ac2d..02a159f 100644 --- a/forgot_password/__init__.py +++ b/forgot_password/__init__.py @@ -16,14 +16,16 @@ import skygear from skygear import error as skyerror from skygear.error import SkygearException +from skygear.settings import settings as sky_config from skygear.utils.db import conn +from . import options # noqa Register the config to skygear on import from . import template from .util import email as emailutil from .util import user as userutil -from .options import options as forgetoptions +forgetoptions = sky_config.forgot_password logger = logging.getLogger(__name__) @@ -34,7 +36,6 @@ def mail_is_configured(): return bool(forgetoptions.smtp_host) -@skygear.op('user:forgot-password') def forgot_password(email): """ Lambda function to handle forgot password request. @@ -108,7 +109,6 @@ def forgot_password(email): return {'status': 'OK'} -@skygear.op('user:reset-password') def reset_password(user_id, code, new_password): """ Lambda function to handle reset password request. @@ -146,7 +146,6 @@ def reset_password_response(**kwargs): return skygear.Response(body, content_type='text/html') -@skygear.handler('reset-password') def reset_password_handler(request): """ A handler for handling reset password request. @@ -194,3 +193,13 @@ def reset_password_handler(request): return skygear.Response(body, content_type='text/html') return reset_password_response(**template_params) + + +def init(): + skygear.op('user:forgot-password')(forgot_password) + skygear.op('user:reset-password')(reset_password) + skygear.handler('reset-password')(reset_password_handler) + + +if forgetoptions.enable: + init() diff --git a/forgot_password/options.py b/forgot_password/options.py index c93ece4..7e59d44 100644 --- a/forgot_password/options.py +++ b/forgot_password/options.py @@ -25,6 +25,5 @@ parser.add_setting('smtp_login', required=False) parser.add_setting('smtp_password', required=False) -add_parser('forgot_password', parser) - -options = settings.forgot_password +if not hasattr(settings, 'forgot_password'): + add_parser('forgot_password', parser)