Skip to content

Commit

Permalink
Use settings to determine register to skygear or not
Browse files Browse the repository at this point in the history
Take away the assumption on register on import, which give more
flexibility on how the plugin to be deploy

refs SkygearIO#5
  • Loading branch information
rickmak committed Sep 29, 2016
1 parent 40673ee commit 265055c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .forgot_password import *
from .forgot_password import init

init()
17 changes: 13 additions & 4 deletions forgot_password/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
5 changes: 2 additions & 3 deletions forgot_password/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 265055c

Please sign in to comment.