-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* If a user tries to change a password for an account and enters the existing password, the operation is now idempotent. Similarly, if an admin "changes" a user's username to itself, this operation is also idempotent. The new `commit_account_changes` function only writes to the database if the `db.User` object of the user's account being changed has been locally modified, which it determines via the `Session.is_modified(db.User)` method. * The `/admin/edit/<int:user_id>` and `/account` routes now use the same template. Since the former provides a superset of the functionality of the latter, and there is no security risk in doing so, DRYing out the templates here made sense. While this fixes #1597, combining the templates also has potential to expose elements meant for admins to users in some future regression. To defend against this, I introduced a new functional test module, `tests.functional.make_account_changes`, which provides comprehensive checks to this regard. I also did some DRYing of these route functions since they both change passwords, commit account changes to the database, and flash messages regarding the success or failure of these operations. * I also made some improvements to the relevant flashed messages for account changes, making progress towards #1476, #1601, #1602. It seemed like "success" and "failure" were better categorical indicators than "notification" and "failure," so I went with that and used the green checkmark PNG we have already employed in the source interface. I changed all the flashed icons here to PNGs while I was at it to make a small step towards making the JI security-slider-friendly, and explicitly specified their sizes to make sure they rendered correctly. * Changing some of the flashed messages in the process of my refactor, I had to change the corresponding unit tests as well. To test both the content and category of the flashed message, I decided to take advantage of Flask-Testing's `assertMessageFlashed` method. This required installing an additional testing dependency, `blinker`, which I did without changing any other package versions.
- Loading branch information
1 parent
c8748a3
commit c56e8ef
Showing
10 changed files
with
211 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
{% extends "base.html" %} | ||
{% block body %} | ||
{% if user %} | ||
<h1>Edit user "{{ user.username }}"</h1> | ||
<p><a href="/admin">« Back to admin interface</a></p> | ||
{% else %} | ||
<h1>Edit your account</h1> | ||
{% endif %} | ||
|
||
<form method="post"> | ||
<input name="csrf_token" type="hidden" value="{{ csrf_token() }}"/> | ||
{% if user %} | ||
<p> | ||
<label for="username">Change username</label> | ||
<input name="username" id="username" type="text" placeholder="{{ user.username }}" /> | ||
</p> | ||
{% endif %} | ||
<p> | ||
<label for="password">Change password</label> | ||
<input name="password" id="password" type="password" /> | ||
{% if user %} | ||
<em class="light">Leave blank for no change</em> | ||
{% endif %} | ||
</p> | ||
<p> | ||
<label for="password_again">Change password (confirm)</label> | ||
<input name="password_again" id="password_again" type="password" /> | ||
</p> | ||
{% if user %} | ||
<p> | ||
<input name="is_admin" id="is_admin" type="checkbox" {% if user.is_admin %}checked{% endif %} /> | ||
<label for="is_admin">Is Administrator</label> | ||
</p> | ||
{% endif %} | ||
{% if user %} | ||
<button class="sd-button" type="submit" id="update-user">UPDATE USER</button> | ||
{% else %} | ||
<button class="sd-button" type="submit" id="update">UPDATE</button> | ||
{% endif %} | ||
</form> | ||
|
||
<hr class="no-line"> | ||
|
||
<h2>Reset Two Factor Authentication</h2> | ||
{% if user %} | ||
<p>If a user's two factor authentication credentials have been lost or compromised, you can reset them here. <em>If you do this, make sure the user is present and ready to set up their device with the new two factor credentials. Otherwise, they will be locked out of their account.</em></p> | ||
<form method="post" action="{{ url_for('admin_reset_two_factor_totp') }}" id="reset-two-factor-totp"> | ||
<input name="uid" type="hidden" value="{{ user.id }}"/> | ||
{% else %} | ||
<p>If your two factor authentication credentials have been lost or compromised, or you got a new device, you can reset your credentials here. <em>If you do this, make sure you are ready to set up your new device, otherwise you will be locked out of your account.</em></p> | ||
<form method="post" action="{{ url_for('account_reset_two_factor_totp') }}" id="reset-two-factor-totp"> | ||
{% endif %} | ||
<input name="csrf_token" type="hidden" value="{{ csrf_token() }}"/> | ||
<button class="sd-button" type="submit" class="pull-right">RESET TWO FACTOR AUTHENTICATION (GOOGLE AUTHENTICATOR)</button> | ||
<button class="sd-button" type="submit" class="pull-right">RESET TWO FACTOR AUTHENTICATION (APP)</button> | ||
</form> | ||
<br /> | ||
{% if user %} | ||
<form method="post" action="{{ url_for('admin_reset_two_factor_hotp') }}" id="reset-two-factor-hotp"> | ||
<input name="uid" type="hidden" value="{{ user.id }}"/> | ||
{% else %} | ||
<form method="post" action="{{ url_for('account_reset_two_factor_hotp') }}" id="reset-two-factor-hotp"> | ||
{% endif %} | ||
<input name="csrf_token" type="hidden" value="{{ csrf_token() }}"/> | ||
<button class="sd-button" type="submit" class="pull-right">RESET TWO FACTOR AUTHENTICATION (HOTP YUBIKEY)</button> | ||
<button class="sd-button" type="submit" class="pull-right">RESET TWO FACTOR AUTHENTICATION (HARDWARE TOKEN)</button> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
beautifulsoup4 | ||
blinker | ||
coveralls | ||
Flask-Testing | ||
mock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.