Holger Frey
7 years ago
13 changed files with 364 additions and 30 deletions
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
{% extends "ordr:templates/layout.jinja2" %} |
||||
|
||||
{% block content %} |
||||
<div class="row justify-content-md-center mt-3"> |
||||
<div class="col-6"> |
||||
<h1>Forgot Your Password?</h1> |
||||
</div> |
||||
</div> |
||||
<div class="row justify-content-md-center mt-3"> |
||||
<div class="col-2"> |
||||
<p class="text-secondary"> |
||||
Step 1: Validate Account |
||||
</p> |
||||
</div> |
||||
<div class="col-2"> |
||||
<p class="text-secondary"> |
||||
Step 2: Change Password |
||||
</p> |
||||
</div> |
||||
<div class="col-2"> |
||||
<p class="text-primary"> |
||||
Step 3: Finished |
||||
</p> |
||||
</div> |
||||
</div> |
||||
<div class="row justify-content-md-center mt-3"> |
||||
<div class="col-6"> |
||||
<h3>Password Reset Succesfull</h3> |
||||
<p class="mt-3">Your password has been changed.</p> |
||||
<p>You can now <a href="{{ request.resource_url(request.root) }}">log in</a> again.</p> |
||||
</div> |
||||
</div> |
||||
{% endblock content %} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
{% extends "ordr:templates/layout.jinja2" %} |
||||
|
||||
{% block content %} |
||||
<div class="row justify-content-md-center mt-3"> |
||||
<div class="col-6"> |
||||
<h1>Forgot Your Password?</h1> |
||||
</div> |
||||
</div> |
||||
<div class="row justify-content-md-center mt-3"> |
||||
<div class="col-2"> |
||||
<p class="text-secondary"> |
||||
Step 1: Validate Account |
||||
</p> |
||||
</div> |
||||
<div class="col-2"> |
||||
<p class="text-primary"> |
||||
Step 2: Change Password |
||||
</p> |
||||
</div> |
||||
<div class="col-2"> |
||||
<p class="text-secondary"> |
||||
Step 3: Finished |
||||
</p> |
||||
</div> |
||||
</div> |
||||
<div class="row justify-content-md-center mt-3"> |
||||
<div class="col-6"> |
||||
<h3>Change your password</h3> |
||||
<p class="mt-3">{{ form.render()|safe }}</p> |
||||
</div> |
||||
</div> |
||||
{% endblock content %} |
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
''' functional tests for ordr2.views.forgotten_password ''' |
||||
|
||||
from pyramid_mailer import get_mailer |
||||
|
||||
from . import testappsetup, testapp, get_token_url # noqa: F401 |
||||
|
||||
|
||||
def test_forgot_password_process(testapp): # noqa: F811 |
||||
''' test the forgot password form ''' |
||||
response = testapp.get('/forgot') |
||||
active_nav = response.html.find('li', class_='active') |
||||
active_step = response.html.find('p', class_='text-primary') |
||||
assert active_nav is None |
||||
assert 'Step 1: Validate Account' in active_step.text |
||||
assert 'Forgot Your Password?' in response |
||||
assert 'unknown username or email' not in response |
||||
|
||||
# fill out this form with invalid data |
||||
form = response.form |
||||
form['identifier'] = 'unknown identifier' |
||||
response = form.submit(name='send_mail') |
||||
active_nav = response.html.find('li', class_='active') |
||||
active_step = response.html.find('p', class_='text-primary') |
||||
assert active_nav is None |
||||
assert 'Step 1: Validate Account' in active_step.text |
||||
assert 'Forgot Your Password?' in response |
||||
assert 'Username or email address unknown' in response |
||||
|
||||
# fill out this form with valid data |
||||
form = response.form |
||||
form['identifier'] = 'TerryGilliam' |
||||
response = form.submit(name='send_mail') |
||||
assert response.location == 'http://localhost/forgot/verify' |
||||
|
||||
response = response.follow() |
||||
active_nav = response.html.find('li', class_='active') |
||||
active_step = response.html.find('p', class_='text-primary') |
||||
assert active_nav is None |
||||
assert 'Step 1: Validate Account' in active_step.text |
||||
assert 'Verify Your Email Address' in response |
||||
|
||||
# click the email verification token |
||||
mailer = get_mailer(testapp.app.registry) |
||||
email = mailer.outbox[-1] |
||||
assert email.subject == '[ordr] Password Reset' |
||||
|
||||
token_link = get_token_url(email, prefix='/forgot/') |
||||
response = testapp.get(token_link) |
||||
active_nav = response.html.find('li', class_='active') |
||||
active_step = response.html.find('p', class_='text-primary') |
||||
assert active_nav is None |
||||
assert 'Step 2: Change Password' in active_step.text |
||||
assert 'Forgot Your Password?' in response |
||||
assert 'do not match' not in response |
||||
|
||||
# fill out the change password form with invalid data |
||||
form = response.form |
||||
form['password'] = 'some passwords' |
||||
form['password-confirm'] = 'that do not match' |
||||
response = form.submit(name='change') |
||||
active_nav = response.html.find('li', class_='active') |
||||
active_step = response.html.find('p', class_='text-primary') |
||||
assert active_nav is None |
||||
assert 'Step 2: Change Password' in active_step.text |
||||
assert 'Forgot Your Password?' in response |
||||
assert 'Password did not match confirm' in response |
||||
|
||||
# fill out the change password form with valid data |
||||
form = response.form |
||||
form['password'] = 'Lost in La Mancha' |
||||
form['password-confirm'] = 'Lost in La Mancha' |
||||
response = form.submit(name='change') |
||||
assert response.location == 'http://localhost/forgot/completed' |
||||
|
||||
response = response.follow() |
||||
active_nav = response.html.find('li', class_='active') |
||||
active_step = response.html.find('p', class_='text-primary') |
||||
content = response.html.find('div', class_='content') |
||||
assert active_nav is None |
||||
assert 'Step 3: Finished' in active_step.text |
||||
assert 'Forgot Your Password?' in response |
||||
assert 'Password Reset Succesfull' in response |
||||
assert content.a['href'] == 'http://localhost/' |
||||
assert content.a.text == 'log in' |
||||
|
||||
# old password should not work but the new one |
||||
assert not testapp.login('TerryGilliam', 'Terry') |
||||
assert testapp.login('TerryGilliam', 'Lost in La Mancha') |
Reference in new issue