Merged in feature/confirmation_redirection (pull request #39)

Add redirection to frontend on email activation
develop
Ensar Sarajcic 2018-10-31 20:45:43 +00:00
commit 83116c28c6
4 changed files with 20 additions and 7 deletions

View File

@ -33,15 +33,15 @@ def confirm_email_token(token):
try:
email = confirm_token(token)
except Exception:
return False
return False, None
user = Account.query.filter_by(email=email).first_or_404()
if user.confirmed:
return True
return True, user.email
else:
user.confirmed = True
user.confirmed_on = datetime.datetime.now()
user.save()
return True
return True, user.email
def update_account_role(account_id, role_id):

View File

@ -1,5 +1,5 @@
from flask_restful import Resource, abort
from flask import g, render_template
from flask import g, render_template, redirect
from marshmallow import Schema, fields
from webargs.flaskparser import use_args
from flasgger import swag_from
@ -10,6 +10,7 @@ from app.api.auth_protection import ProtectedResource
from app.api.permission_protection import (requires_permission,
valid_permissions)
from app.api.schemas import BaseResourceSchema
from flask import current_app as app
class UserSchema(BaseResourceSchema):
@ -107,10 +108,15 @@ class AccountListResource(Resource):
class AccountEmailTokenResource(Resource):
def get(self, token):
success = accounts.confirm_email_token(token)
success, email = accounts.confirm_email_token(token)
if success:
return '{"status": "success", \
"message": "Successfully confirmed email"}', 200
html = render_template(
'welcome_to_iot.html')
send_email_task.delay(
email,
'Welcome to IoT!',
html)
return redirect(app.config['FRONTEND_URL'])
class AccountEmailTokenResendResource(Resource):

View File

@ -0,0 +1,3 @@
<p>Welcome! Thanks for signing up! You have successfully confirmed your email.</p>
<br>
<p>Cheers!</p>

View File

@ -55,6 +55,10 @@ MAIL_PASSWORD = os.environ['APP_MAIL_PASSWORD']
# mail accounts
MAIL_DEFAULT_SENDER = 'final.iot.backend.mailer@gmail.com'
# frontend
FRONTEND_URL = (os.environ.get('IOT_FRONTEND_URL') or
'http://iot-frontend-app.herokuapp.com/')
# Flasgger config
SWAGGER = {
'uiversion': 3