Merged in feature/confirmation_redirection (pull request #39)
Add redirection to frontend on email activationdevelop
commit
83116c28c6
|
@ -33,15 +33,15 @@ def confirm_email_token(token):
|
||||||
try:
|
try:
|
||||||
email = confirm_token(token)
|
email = confirm_token(token)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False, None
|
||||||
user = Account.query.filter_by(email=email).first_or_404()
|
user = Account.query.filter_by(email=email).first_or_404()
|
||||||
if user.confirmed:
|
if user.confirmed:
|
||||||
return True
|
return True, user.email
|
||||||
else:
|
else:
|
||||||
user.confirmed = True
|
user.confirmed = True
|
||||||
user.confirmed_on = datetime.datetime.now()
|
user.confirmed_on = datetime.datetime.now()
|
||||||
user.save()
|
user.save()
|
||||||
return True
|
return True, user.email
|
||||||
|
|
||||||
|
|
||||||
def update_account_role(account_id, role_id):
|
def update_account_role(account_id, role_id):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from flask_restful import Resource, abort
|
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 marshmallow import Schema, fields
|
||||||
from webargs.flaskparser import use_args
|
from webargs.flaskparser import use_args
|
||||||
from flasgger import swag_from
|
from flasgger import swag_from
|
||||||
|
@ -10,6 +10,7 @@ from app.api.auth_protection import ProtectedResource
|
||||||
from app.api.permission_protection import (requires_permission,
|
from app.api.permission_protection import (requires_permission,
|
||||||
valid_permissions)
|
valid_permissions)
|
||||||
from app.api.schemas import BaseResourceSchema
|
from app.api.schemas import BaseResourceSchema
|
||||||
|
from flask import current_app as app
|
||||||
|
|
||||||
|
|
||||||
class UserSchema(BaseResourceSchema):
|
class UserSchema(BaseResourceSchema):
|
||||||
|
@ -107,10 +108,15 @@ class AccountListResource(Resource):
|
||||||
|
|
||||||
class AccountEmailTokenResource(Resource):
|
class AccountEmailTokenResource(Resource):
|
||||||
def get(self, token):
|
def get(self, token):
|
||||||
success = accounts.confirm_email_token(token)
|
success, email = accounts.confirm_email_token(token)
|
||||||
if success:
|
if success:
|
||||||
return '{"status": "success", \
|
html = render_template(
|
||||||
"message": "Successfully confirmed email"}', 200
|
'welcome_to_iot.html')
|
||||||
|
send_email_task.delay(
|
||||||
|
email,
|
||||||
|
'Welcome to IoT!',
|
||||||
|
html)
|
||||||
|
return redirect(app.config['FRONTEND_URL'])
|
||||||
|
|
||||||
|
|
||||||
class AccountEmailTokenResendResource(Resource):
|
class AccountEmailTokenResendResource(Resource):
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<p>Welcome! Thanks for signing up! You have successfully confirmed your email.</p>
|
||||||
|
<br>
|
||||||
|
<p>Cheers!</p>
|
|
@ -55,6 +55,10 @@ MAIL_PASSWORD = os.environ['APP_MAIL_PASSWORD']
|
||||||
# mail accounts
|
# mail accounts
|
||||||
MAIL_DEFAULT_SENDER = 'final.iot.backend.mailer@gmail.com'
|
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
|
# Flasgger config
|
||||||
SWAGGER = {
|
SWAGGER = {
|
||||||
'uiversion': 3
|
'uiversion': 3
|
||||||
|
|
Loading…
Reference in New Issue