Files
notifications-admin/app/main/views/verify.py
Adam Shimali 6ba13a6513 [WIP] New user can now accept invite and will be made to
register. On succesful register and verfication they
will be added to service and forwarded to dashboard.

Nothing is done yet with the permissions requested in the
invite to the user.
2016-03-02 17:52:32 +00:00

43 lines
1.1 KiB
Python

from flask import (
render_template,
redirect,
session,
url_for,
abort
)
from notifications_python_client.errors import HTTPError
from flask_login import login_user
from app.main import main
from app.main.dao import users_dao
from app.main.forms import VerifyForm
@main.route('/verify', methods=['GET', 'POST'])
def verify():
# TODO there needs to be a way to regenerate a session id
# or handle gracefully.
user_id = session['user_details']['id']
def _check_code(code, code_type):
return users_dao.check_verify_code(user_id, code, code_type)
form = VerifyForm(_check_code)
if form.validate_on_submit():
try:
user = users_dao.get_user_by_id(user_id)
activated_user = users_dao.activate_user(user)
login_user(activated_user)
return redirect(url_for('main.add_service', first='first'))
except HTTPError as e:
if e.status_code == 404:
abort(404)
else:
raise e
finally:
del session['user_details']
return render_template('views/verify.html', form=form)