Working tests, hopefully all code changes done.

This commit is contained in:
Nicholas Staples
2016-01-27 12:22:32 +00:00
parent ce81a6f540
commit 6959d695d3
57 changed files with 1143 additions and 1578 deletions

View File

@@ -1,8 +1,10 @@
from flask import (
request, render_template, redirect, url_for, session)
from flask.ext.login import current_user
from flask_login import login_required
from app.main import main
from app.main.dao.users_dao import (verify_password, update_user)
from app.main.dao.users_dao import (
verify_password, update_user, check_verify_code, is_email_unique)
from app.main.forms import (
ChangePasswordForm, ChangeNameForm, ChangeEmailForm, ConfirmEmailForm,
ChangeMobileNumberForm, ConfirmMobileNumberForm, ConfirmPasswordForm
@@ -15,17 +17,19 @@ NEW_MOBILE_PASSWORD_CONFIRMED = 'new-mob-password-confirmed'
@main.route("/user-profile")
@login_required
def user_profile():
return render_template('views/user-profile.html')
@main.route("/user-profile/name", methods=['GET', 'POST'])
@login_required
def user_profile_name():
form = ChangeNameForm(new_name=current_user.name)
if form.validate_on_submit():
current_user.name = form.new_name
current_user.name = form.new_name.data
update_user(current_user)
return redirect(url_for('.user_profile'))
@@ -37,9 +41,13 @@ def user_profile_name():
@main.route("/user-profile/email", methods=['GET', 'POST'])
@login_required
def user_profile_email():
form = ChangeEmailForm(email_address=current_user.email_address)
def _is_email_unique(email):
return is_email_unique(email)
form = ChangeEmailForm(_is_email_unique,
email_address=current_user.email_address)
if form.validate_on_submit():
session[NEW_EMAIL] = form.email_address.data
@@ -52,6 +60,7 @@ def user_profile_email():
@main.route("/user-profile/email/authenticate", methods=['GET', 'POST'])
@login_required
def user_profile_email_authenticate():
# Validate password for form
@@ -75,18 +84,21 @@ def user_profile_email_authenticate():
@main.route("/user-profile/email/confirm", methods=['GET', 'POST'])
@login_required
def user_profile_email_confirm():
# TODO add verify code support
form = ConfirmEmailForm()
# Validate verify code for form
def _check_code(cde):
return check_verify_code(current_user.id, cde, 'email')
form = ConfirmEmailForm(_check_code)
if NEW_EMAIL_PASSWORD_CONFIRMED not in session:
return redirect('main.user_profile_email_authenticate')
if form.validate_on_submit():
current_user.email_address = session[NEW_EMAIL]
del session[NEW_EMAIL]
del session[NEW_EMAIL_PASSWORD_CONFIRMED]
current_user.email_address = session['new_email']
update_user(current_user)
return redirect(url_for('.user_profile'))
@@ -98,6 +110,7 @@ def user_profile_email_confirm():
@main.route("/user-profile/mobile-number", methods=['GET', 'POST'])
@login_required
def user_profile_mobile_number():
form = ChangeMobileNumberForm(mobile_number=current_user.mobile_number)
@@ -114,6 +127,7 @@ def user_profile_mobile_number():
@main.route("/user-profile/mobile-number/authenticate", methods=['GET', 'POST'])
@login_required
def user_profile_mobile_number_authenticate():
# Validate password for form
@@ -137,14 +151,22 @@ def user_profile_mobile_number_authenticate():
@main.route("/user-profile/mobile-number/confirm", methods=['GET', 'POST'])
@login_required
def user_profile_mobile_number_confirm():
form = ConfirmMobileNumberForm()
# Validate verify code for form
def _check_code(cde):
return check_verify_code(current_user, cde, 'sms')
if NEW_MOBILE_PASSWORD_CONFIRMED not in session:
return redirect(url_for('.user_profile_mobile_number'))
form = ConfirmMobileNumberForm(_check_code)
if form.validate_on_submit():
current_user.mobile = session[NEW_MOBILE]
del session[NEW_MOBILE]
del session[NEW_MOBILE_PASSWORD_CONFIRMED]
current_user.mobile_user
update_user(current_user)
return redirect(url_for('.user_profile'))
@@ -156,11 +178,17 @@ def user_profile_mobile_number_confirm():
@main.route("/user-profile/password", methods=['GET', 'POST'])
@login_required
def user_profile_password():
form = ChangePasswordForm()
# Validate password for form
def _check_password(pwd):
return verify_password(current_user, pwd)
form = ChangePasswordForm(_check_password)
if form.validate_on_submit():
current_user.set_password(form.new_password.data)
update_user(current_user)
return redirect(url_for('.user_profile'))
return render_template(