mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
User registration now creates user via api.
Verification flow is still to be completed. Foreign key constraint on verify codes to user table removed.
This commit is contained in:
@@ -15,7 +15,7 @@ from app.models import User
|
||||
from app.main.dao import users_dao
|
||||
from app.main.forms import RegisterUserForm
|
||||
|
||||
from app.notify_client.user_api_client import UserApiClient
|
||||
from app import user_api_client
|
||||
|
||||
# TODO how do we handle duplicate unverifed email addresses?
|
||||
# malicious or otherwise.
|
||||
@@ -28,23 +28,11 @@ def register():
|
||||
|
||||
if form.validate_on_submit():
|
||||
|
||||
# TODO remove once all api integrations done
|
||||
user = User(name=form.name.data,
|
||||
email_address=form.email_address.data,
|
||||
mobile_number=form.mobile_number.data,
|
||||
password=form.password.data,
|
||||
created_at=datetime.now(),
|
||||
role_id=1)
|
||||
users_dao.insert_user(user)
|
||||
|
||||
user_api_client = UserApiClient(current_app.config['API_HOST_NAME'],
|
||||
current_app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
current_app.config['ADMIN_CLIENT_SECRET'])
|
||||
try:
|
||||
user_api_client.register_user(form.name.data,
|
||||
form.email_address.data,
|
||||
form.mobile_number.data,
|
||||
form.password.data)
|
||||
user = user_api_client.register_user(form.name.data,
|
||||
form.email_address.data,
|
||||
form.mobile_number.data,
|
||||
form.password.data)
|
||||
except HTTPError as e:
|
||||
if e.status_code == 404:
|
||||
abort(404)
|
||||
@@ -56,10 +44,10 @@ def register():
|
||||
# How do we report to the user there is a problem with
|
||||
# sending codes apart from service unavailable?
|
||||
# at the moment i believe http 500 is fine.
|
||||
send_sms_code(user_id=user.id, mobile_number=form.mobile_number.data)
|
||||
send_email_code(user_id=user.id, email=form.email_address.data)
|
||||
send_sms_code(user_id=user.id, mobile_number=user.mobile_number)
|
||||
send_email_code(user_id=user.id, email=user.email_address)
|
||||
session['expiry_date'] = str(datetime.now() + timedelta(hours=1))
|
||||
session['user_email'] = user.email_address
|
||||
session['user_details'] = {"email": user.email_address, "id": user.id}
|
||||
return redirect('/verify')
|
||||
|
||||
return render_template('views/register.html', form=form)
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
from flask import (
|
||||
render_template, redirect, jsonify, session, url_for)
|
||||
render_template,
|
||||
redirect,
|
||||
jsonify,
|
||||
session,
|
||||
url_for
|
||||
)
|
||||
|
||||
from flask_login import login_user
|
||||
|
||||
@@ -12,13 +17,16 @@ from app.main.forms import VerifyForm
|
||||
def verify():
|
||||
# TODO there needs to be a way to regenerate a session id
|
||||
# or handle gracefully.
|
||||
user = users_dao.get_user_by_email(session['user_email'])
|
||||
codes = verify_codes_dao.get_codes(user.id)
|
||||
user_id = session['user_details']['id']
|
||||
codes = verify_codes_dao.get_codes(user_id)
|
||||
form = VerifyForm(codes)
|
||||
if form.validate_on_submit():
|
||||
verify_codes_dao.use_code_for_user_and_type(user_id=user.id, code_type='email')
|
||||
verify_codes_dao.use_code_for_user_and_type(user_id=user.id, code_type='sms')
|
||||
users_dao.activate_user(user.id)
|
||||
login_user(user)
|
||||
verify_codes_dao.use_code_for_user_and_type(user_id=user_id, code_type='email')
|
||||
verify_codes_dao.use_code_for_user_and_type(user_id=user_id, code_type='sms')
|
||||
|
||||
# TODO complete verify and login flow
|
||||
# users_dao.activate_user(user.id)
|
||||
# login_user(user)
|
||||
|
||||
return redirect(url_for('.add_service', first='first'))
|
||||
return render_template('views/verify.html', form=form)
|
||||
|
||||
Reference in New Issue
Block a user