From a52d431e0dfe25233001c11119ac4e9e0930839b Mon Sep 17 00:00:00 2001 From: androiddrew Date: Fri, 16 Feb 2018 15:22:11 -0500 Subject: [PATCH] Included support for apistar-mail --- cookie_api/app.py | 5 ++++- cookie_api/auth.py | 10 +++++++--- requirements.txt | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/cookie_api/app.py b/cookie_api/app.py index 2f28437..e2d0a89 100644 --- a/cookie_api/app.py +++ b/cookie_api/app.py @@ -6,6 +6,8 @@ from apistar.handlers import docs_urls, static_urls from apistar.interfaces import Router, Injector, Auth from apistar_jwt.authentication import JWTAuthentication from apistar_alembic_migrations import commands as migrate_commands +from apistar_mail import mail_component + import logbook @@ -81,7 +83,8 @@ _routes = _routes + auth_routes _commands = sqlalchemy_backend.commands + commands + migrate_commands -_components = sqlalchemy_backend.components + auth_components + +_components = sqlalchemy_backend.components + auth_components + [mail_component] def application_factory(settings={}, routes=_routes, commands=_commands, components=_components): diff --git a/cookie_api/auth.py b/cookie_api/auth.py index 94f16bc..de83240 100644 --- a/cookie_api/auth.py +++ b/cookie_api/auth.py @@ -4,8 +4,10 @@ from apistar import Component, Settings, http, Route, Include from apistar.backends.sqlalchemy_backend import Session from apistar_jwt.authentication import get_jwt from apistar_jwt.token import JWT +from apistar_mail import Message, Mail from sqlalchemy.exc import IntegrityError, InvalidRequestError + from cookie_api.models import User auth_components = [ @@ -47,7 +49,7 @@ def logout(): # TODO Add user registration -def register(settings: Settings, json_data: http.RequestData, session: Session): +def register(json_data: http.RequestData, session: Session, mail:Mail): user_id = json_data.get('email') password = json_data.get('password') @@ -65,7 +67,9 @@ def register(settings: Settings, json_data: http.RequestData, session: Session): session.add(user) session.commit() - # TODO Send off an email confirmation + msg = Message("Thank you for registering please confirm your email", recipients=[user_id]) + mail.send(msg) + headers = {} message = { 'status': 'success', @@ -80,7 +84,7 @@ def user_profile(): # TODO Add email confirmation -def confirm(settings: Settings, json_data: http.RequestData, session: Session): +def confirm(json_data: http.RequestData, session: Session): pass diff --git a/requirements.txt b/requirements.txt index 8c6f0b9..7486ced 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,3 +30,37 @@ uritemplate==3.0.0 urllib3==1.22 Werkzeug==0.12.2 whitenoise==3.3.1 +alembic==0.9.6 +apistar==0.3.9 +apistar-alembic-migrations==0.0.6 +apistar-jwt==0.2.1 +apistar-mail==0.2.0 +bcrypt==3.1.4 +certifi==2017.7.27.1 +cffi==1.11.2 +chardet==3.0.4 +colorama==0.3.9 +coreapi==2.3.3 +coreschema==0.0.4 +idna==2.6 +itsdangerous==0.24 +itypes==1.1.0 +Jinja2==2.9.6 +Logbook==1.1.0 +Mako==1.0.7 +MarkupSafe==1.0 +marshmallow==2.15.0 +psycopg2==2.7.3.1 +py==1.4.34 +pycparser==2.18 +PyJWT==1.5.3 +pytest==3.2.3 +python-dateutil==2.6.1 +python-editor==1.0.3 +requests==2.18.4 +six==1.11.0 +SQLAlchemy==1.1.14 +uritemplate==3.0.0 +urllib3==1.22 +Werkzeug==0.12.2 +whitenoise==3.3.1