mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Add loops for changing each part of your profile
This commit adds a page or series of pages for changing your:
Name | Email address | Mobile number | Password
------------------|-------------------|-------------------|------------
Enter new value | Enter new value | Enter new value | Enter new value
| Enter 2fa code | Enter 2fa code |
Return to profile | Return to profile | Return to profile | Return to profile
(each row is a page)
This commit is contained in:
@@ -155,3 +155,23 @@ class NewPasswordForm(Form):
|
|||||||
class CsvUploadForm(Form):
|
class CsvUploadForm(Form):
|
||||||
file = FileField('File to upload', validators=[DataRequired(
|
file = FileField('File to upload', validators=[DataRequired(
|
||||||
message='Please pick a file'), CsvFileValidator()])
|
message='Please pick a file'), CsvFileValidator()])
|
||||||
|
|
||||||
|
|
||||||
|
class ChangeNameForm(Form):
|
||||||
|
new_name = StringField(u'Your name')
|
||||||
|
|
||||||
|
|
||||||
|
class ChangeEmailForm(Form):
|
||||||
|
email_address = email_address()
|
||||||
|
|
||||||
|
|
||||||
|
class ConfirmEmailForm(Form):
|
||||||
|
email_code = email_code()
|
||||||
|
|
||||||
|
|
||||||
|
class ChangeMobileNumberForm(Form):
|
||||||
|
mobile_number = mobile_number()
|
||||||
|
|
||||||
|
|
||||||
|
class ConfirmMobileNumberForm(Form):
|
||||||
|
sms_code = sms_code()
|
||||||
|
|||||||
@@ -1,7 +1,108 @@
|
|||||||
from flask import render_template
|
from flask import request, render_template, redirect, url_for
|
||||||
|
from flask.ext.login import current_user
|
||||||
from app.main import main
|
from app.main import main
|
||||||
|
from app.main.forms import (
|
||||||
|
NewPasswordForm, ChangeNameForm, ChangeEmailForm, ConfirmEmailForm,
|
||||||
|
ChangeMobileNumberForm, ConfirmMobileNumberForm
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/user-profile")
|
@main.route("/user-profile")
|
||||||
def userprofile():
|
def userprofile():
|
||||||
return render_template('views/user-profile.html')
|
return render_template('views/user-profile.html')
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/user-profile/name", methods=['GET', 'POST'])
|
||||||
|
def userprofile_name():
|
||||||
|
|
||||||
|
form = ChangeNameForm()
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
if current_user.is_authenticated():
|
||||||
|
form.new_name.data = current_user.name
|
||||||
|
return render_template(
|
||||||
|
'views/user-profile/change.html',
|
||||||
|
thing='name',
|
||||||
|
form_field=form.new_name
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
return redirect(url_for('.userprofile'))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/user-profile/email", methods=['GET', 'POST'])
|
||||||
|
def userprofile_email():
|
||||||
|
|
||||||
|
form = ChangeEmailForm()
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
if current_user.is_authenticated():
|
||||||
|
form.email_address.data = current_user.email_address
|
||||||
|
return render_template(
|
||||||
|
'views/user-profile/change.html',
|
||||||
|
thing='email address',
|
||||||
|
form_field=form.email_address
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
return redirect(url_for('.userprofile_email_confirm'))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/user-profile/email/confirm", methods=['GET', 'POST'])
|
||||||
|
def userprofile_email_confirm():
|
||||||
|
|
||||||
|
form = ConfirmEmailForm()
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render_template(
|
||||||
|
'views/user-profile/confirm.html',
|
||||||
|
form_field=form.email_code,
|
||||||
|
thing='email address'
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
return redirect(url_for('.userprofile'))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/user-profile/mobile-number", methods=['GET', 'POST'])
|
||||||
|
def userprofile_mobile_number():
|
||||||
|
|
||||||
|
form = ChangeMobileNumberForm()
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
if current_user.is_authenticated():
|
||||||
|
form.mobile_number.data = current_user.mobile_number
|
||||||
|
return render_template(
|
||||||
|
'views/user-profile/change.html',
|
||||||
|
thing='mobile number',
|
||||||
|
form_field=form.mobile_number
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
return redirect(url_for('.userprofile_mobile_number_confirm'))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/user-profile/mobile-number/confirm", methods=['GET', 'POST'])
|
||||||
|
def userprofile_mobile_number_confirm():
|
||||||
|
|
||||||
|
form = ConfirmMobileNumberForm()
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render_template(
|
||||||
|
'views/user-profile/confirm.html',
|
||||||
|
form_field=form.sms_code,
|
||||||
|
thing='mobile number'
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
return redirect(url_for('.userprofile'))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/user-profile/password", methods=['GET', 'POST'])
|
||||||
|
def userprofile_password():
|
||||||
|
|
||||||
|
form = NewPasswordForm()
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render_template(
|
||||||
|
'views/user-profile/change.html',
|
||||||
|
thing='password',
|
||||||
|
form_field=form.new_password
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
return redirect(url_for('.userprofile'))
|
||||||
|
|||||||
31
app/templates/views/user-profile/change.html
Normal file
31
app/templates/views/user-profile/change.html
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{% extends "withnav_template.html" %}
|
||||||
|
{% from "components/textbox.html" import textbox %}
|
||||||
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
|
|
||||||
|
{% block page_title %}
|
||||||
|
GOV.UK Notify | Service settings
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
|
<h1 class="heading-xlarge">Change your {{ thing }}</h1>
|
||||||
|
|
||||||
|
<div class="grid-row">
|
||||||
|
{% if preamble %}
|
||||||
|
<p>
|
||||||
|
{{ preamble }}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
<div class="column-three-quarters">
|
||||||
|
<form method="post">
|
||||||
|
{{ textbox(form_field) }}
|
||||||
|
{{ page_footer(
|
||||||
|
'Save',
|
||||||
|
back_link=url_for('.userprofile'),
|
||||||
|
back_link_text="Back to your profile"
|
||||||
|
) }}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
29
app/templates/views/user-profile/confirm.html
Normal file
29
app/templates/views/user-profile/confirm.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends "withnav_template.html" %}
|
||||||
|
{% from "components/textbox.html" import textbox %}
|
||||||
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
|
|
||||||
|
{% block page_title %}
|
||||||
|
GOV.UK Notify | Service settings
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
|
<h1 class="heading-xlarge">Change your {{ thing }}</h1>
|
||||||
|
|
||||||
|
<div class="grid-row">
|
||||||
|
<div class="column-three-quarters">
|
||||||
|
<p>
|
||||||
|
We’ve sent a code to your new {{ thing }}.
|
||||||
|
</p>
|
||||||
|
<form method="post">
|
||||||
|
{{ textbox(form_field) }}
|
||||||
|
{{ page_footer(
|
||||||
|
'Confirm',
|
||||||
|
destructive=destructive,
|
||||||
|
back_link=url_for('.service_settings')
|
||||||
|
) }}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -3,3 +3,89 @@ def test_should_show_overview_page(notifications_admin):
|
|||||||
|
|
||||||
assert 'Your profile' in response.get_data(as_text=True)
|
assert 'Your profile' in response.get_data(as_text=True)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_name_page(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().get('/user-profile/name')
|
||||||
|
|
||||||
|
assert 'Change your name' in response.get_data(as_text=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_after_name_change(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().post('/user-profile/name')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/user-profile'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_email_page(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().get('/user-profile/email')
|
||||||
|
|
||||||
|
assert 'Change your email address' in response.get_data(as_text=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_after_email_change(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().post('/user-profile/email')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/user-profile/email/confirm'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_confirm_after_email_change(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().get('/user-profile/email/confirm')
|
||||||
|
|
||||||
|
assert 'Change your email address' in response.get_data(as_text=True)
|
||||||
|
assert 'Confirm' in response.get_data(as_text=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_after_email_change_confirm(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().post('/user-profile/email/confirm')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/user-profile'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_mobile_number_page(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().get('/user-profile/mobile-number')
|
||||||
|
|
||||||
|
assert 'Change your mobile number' in response.get_data(as_text=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_after_mobile_number_change(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().post('/user-profile/email')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/user-profile/email/confirm'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_confirm_after_mobile_number_change(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().get('/user-profile/mobile-number/confirm')
|
||||||
|
|
||||||
|
assert 'Change your mobile number' in response.get_data(as_text=True)
|
||||||
|
assert 'Confirm' in response.get_data(as_text=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_after_mobile_number_confirm(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().post('/user-profile/mobile-number/confirm')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/user-profile'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_password_page(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().get('/user-profile/password')
|
||||||
|
|
||||||
|
assert 'Change your password' in response.get_data(as_text=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_after_password_change(notifications_admin):
|
||||||
|
response = notifications_admin.test_client().post('/user-profile/password')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/user-profile'
|
||||||
|
|||||||
Reference in New Issue
Block a user