diff --git a/app/accounts/api.py b/app/accounts/api.py index b1a1d57..76cf236 100644 --- a/app/accounts/api.py +++ b/app/accounts/api.py @@ -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): diff --git a/app/api/resources/account.py b/app/api/resources/account.py index 1eae2ea..9cead0d 100644 --- a/app/api/resources/account.py +++ b/app/api/resources/account.py @@ -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): diff --git a/app/templates/welcome_to_iot.html b/app/templates/welcome_to_iot.html new file mode 100644 index 0000000..0acc6c1 --- /dev/null +++ b/app/templates/welcome_to_iot.html @@ -0,0 +1,3 @@ +
Welcome! Thanks for signing up! You have successfully confirmed your email.
+Cheers!
diff --git a/config.py b/config.py index 890b690..2a1f3ba 100644 --- a/config.py +++ b/config.py @@ -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