forked from Github-Mirrors/canaille
profile edition: redirect after form submission to avoid double submissions
This commit is contained in:
parent
32a626ee4b
commit
c7df0cca32
3 changed files with 16 additions and 29 deletions
|
@ -497,6 +497,7 @@ def profile_edit(editor, username):
|
||||||
flash(_("Profile updated successfuly."), "success")
|
flash(_("Profile updated successfuly."), "success")
|
||||||
|
|
||||||
user.save()
|
user.save()
|
||||||
|
return redirect(url_for("account.profile_edition", username=username))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"profile.html",
|
"profile.html",
|
||||||
|
|
|
@ -186,16 +186,10 @@
|
||||||
|
|
||||||
<div class="ui message warning visible">
|
<div class="ui message warning visible">
|
||||||
{% if has_smtp and edited_user.can_edit_self %}
|
{% if has_smtp and edited_user.can_edit_self %}
|
||||||
{% if request.method == "POST" and request.form.action == "password-initialization-mail" %}
|
|
||||||
<button type="submit" name="action" value="password-initialization-mail" class="ui right floated button">
|
|
||||||
{% trans %}Send again{% endtrans %}
|
|
||||||
</button>
|
|
||||||
{% else %}
|
|
||||||
<button type="submit" name="action" value="password-initialization-mail" class="ui right floated primary button">
|
<button type="submit" name="action" value="password-initialization-mail" class="ui right floated primary button">
|
||||||
{% trans %}Send email{% endtrans %}
|
{% trans %}Send email{% endtrans %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{% trans %}This user does not have a password yet{% endtrans %}
|
{% trans %}This user does not have a password yet{% endtrans %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -215,11 +209,7 @@
|
||||||
|
|
||||||
<div class="ui message info">
|
<div class="ui message info">
|
||||||
<button type="submit" name="action" value="password-reset-mail" class="ui right floated button">
|
<button type="submit" name="action" value="password-reset-mail" class="ui right floated button">
|
||||||
{% if request.method == "POST" and request.form.action == "password-reset-mail" %}
|
|
||||||
{% trans %}Send again{% endtrans %}
|
|
||||||
{% else %}
|
|
||||||
{% trans %}Send mail{% endtrans %}
|
{% trans %}Send mail{% endtrans %}
|
||||||
{% endif %}
|
|
||||||
</button>
|
</button>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{% trans %}Password reset{% endtrans %}
|
{% trans %}Password reset{% endtrans %}
|
||||||
|
|
|
@ -51,7 +51,7 @@ def test_edition(
|
||||||
"cn=bar,ou=groups,dc=mydomain,dc=tld",
|
"cn=bar,ou=groups,dc=mydomain,dc=tld",
|
||||||
]
|
]
|
||||||
res.form["jpegPhoto"] = Upload("logo.jpg", jpeg_photo)
|
res.form["jpegPhoto"] = Upload("logo.jpg", jpeg_photo)
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
assert "Profile updated successfuly." in res, str(res)
|
assert "Profile updated successfuly." in res, str(res)
|
||||||
|
|
||||||
logged_user = User.get(dn=logged_user.dn)
|
logged_user = User.get(dn=logged_user.dn)
|
||||||
|
@ -157,7 +157,7 @@ def test_bad_email(testclient, logged_user):
|
||||||
|
|
||||||
res.form["mail"] = "john@doe.com"
|
res.form["mail"] = "john@doe.com"
|
||||||
|
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
|
|
||||||
assert ["john@doe.com"] == logged_user.mail
|
assert ["john@doe.com"] == logged_user.mail
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ def test_password_change(testclient, logged_user):
|
||||||
res.form["password1"] = "new_password"
|
res.form["password1"] = "new_password"
|
||||||
res.form["password2"] = "new_password"
|
res.form["password2"] = "new_password"
|
||||||
|
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
|
|
||||||
assert logged_user.check_password("new_password")
|
assert logged_user.check_password("new_password")
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ def test_password_change(testclient, logged_user):
|
||||||
res.form["password1"] = "correct horse battery staple"
|
res.form["password1"] = "correct horse battery staple"
|
||||||
res.form["password2"] = "correct horse battery staple"
|
res.form["password2"] = "correct horse battery staple"
|
||||||
|
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
assert "Profile updated successfuly" in res
|
assert "Profile updated successfuly" in res
|
||||||
|
|
||||||
assert logged_user.check_password("correct horse battery staple")
|
assert logged_user.check_password("correct horse battery staple")
|
||||||
|
@ -269,7 +269,7 @@ def test_user_creation_edition_and_deletion(
|
||||||
]
|
]
|
||||||
|
|
||||||
# User have been edited
|
# User have been edited
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
george = User.get("george")
|
george = User.get("george")
|
||||||
george.load_groups()
|
george.load_groups()
|
||||||
assert "Georgio" == george.givenName[0]
|
assert "Georgio" == george.givenName[0]
|
||||||
|
@ -329,14 +329,11 @@ def test_first_login_mail_button(smtpd, testclient, slapd_connection, logged_adm
|
||||||
assert "This user does not have a password yet" in res
|
assert "This user does not have a password yet" in res
|
||||||
assert "Send" in res
|
assert "Send" in res
|
||||||
|
|
||||||
res = res.form.submit(
|
res = res.form.submit(name="action", value="password-initialization-mail").follow()
|
||||||
name="action", value="password-initialization-mail", status=200
|
|
||||||
)
|
|
||||||
assert (
|
assert (
|
||||||
"A password initialization link has been sent at the user email address. It should be received within 10 minutes."
|
"A password initialization link has been sent at the user email address. It should be received within 10 minutes."
|
||||||
in res
|
in res
|
||||||
)
|
)
|
||||||
assert "Send again" in res
|
|
||||||
assert len(smtpd.messages) == 1
|
assert len(smtpd.messages) == 1
|
||||||
|
|
||||||
u.reload()
|
u.reload()
|
||||||
|
@ -365,12 +362,11 @@ def test_email_reset_button(smtpd, testclient, slapd_connection, logged_admin):
|
||||||
assert "If the user has forgotten his password" in res, res.text
|
assert "If the user has forgotten his password" in res, res.text
|
||||||
assert "Send" in res
|
assert "Send" in res
|
||||||
|
|
||||||
res = res.form.submit(name="action", value="password-reset-mail", status=200)
|
res = res.form.submit(name="action", value="password-reset-mail").follow()
|
||||||
assert (
|
assert (
|
||||||
"A password reset link has been sent at the user email address. It should be received within 10 minutes."
|
"A password reset link has been sent at the user email address. It should be received within 10 minutes."
|
||||||
in res
|
in res
|
||||||
)
|
)
|
||||||
assert "Send again" in res
|
|
||||||
assert len(smtpd.messages) == 1
|
assert len(smtpd.messages) == 1
|
||||||
|
|
||||||
u.delete()
|
u.delete()
|
||||||
|
@ -387,7 +383,7 @@ def test_photo_edition(
|
||||||
res = testclient.get("/profile/user", status=200)
|
res = testclient.get("/profile/user", status=200)
|
||||||
res.form["jpegPhoto"] = Upload("logo.jpg", jpeg_photo)
|
res.form["jpegPhoto"] = Upload("logo.jpg", jpeg_photo)
|
||||||
res.form["jpegPhoto_delete"] = False
|
res.form["jpegPhoto_delete"] = False
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
assert "Profile updated successfuly." in res, str(res)
|
assert "Profile updated successfuly." in res, str(res)
|
||||||
|
|
||||||
logged_user = User.get(dn=logged_user.dn)
|
logged_user = User.get(dn=logged_user.dn)
|
||||||
|
@ -397,7 +393,7 @@ def test_photo_edition(
|
||||||
# No change
|
# No change
|
||||||
res = testclient.get("/profile/user", status=200)
|
res = testclient.get("/profile/user", status=200)
|
||||||
res.form["jpegPhoto_delete"] = False
|
res.form["jpegPhoto_delete"] = False
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
assert "Profile updated successfuly." in res, str(res)
|
assert "Profile updated successfuly." in res, str(res)
|
||||||
|
|
||||||
logged_user = User.get(dn=logged_user.dn)
|
logged_user = User.get(dn=logged_user.dn)
|
||||||
|
@ -407,7 +403,7 @@ def test_photo_edition(
|
||||||
# Photo deletion
|
# Photo deletion
|
||||||
res = testclient.get("/profile/user", status=200)
|
res = testclient.get("/profile/user", status=200)
|
||||||
res.form["jpegPhoto_delete"] = True
|
res.form["jpegPhoto_delete"] = True
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
assert "Profile updated successfuly." in res, str(res)
|
assert "Profile updated successfuly." in res, str(res)
|
||||||
|
|
||||||
logged_user = User.get(dn=logged_user.dn)
|
logged_user = User.get(dn=logged_user.dn)
|
||||||
|
@ -418,7 +414,7 @@ def test_photo_edition(
|
||||||
res = testclient.get("/profile/user", status=200)
|
res = testclient.get("/profile/user", status=200)
|
||||||
res.form["jpegPhoto"] = Upload("logo.jpg", jpeg_photo)
|
res.form["jpegPhoto"] = Upload("logo.jpg", jpeg_photo)
|
||||||
res.form["jpegPhoto_delete"] = True
|
res.form["jpegPhoto_delete"] = True
|
||||||
res = res.form.submit(name="action", value="edit", status=200)
|
res = res.form.submit(name="action", value="edit").follow()
|
||||||
assert "Profile updated successfuly." in res, str(res)
|
assert "Profile updated successfuly." in res, str(res)
|
||||||
|
|
||||||
logged_user = User.get(dn=logged_user.dn)
|
logged_user = User.get(dn=logged_user.dn)
|
||||||
|
|
Loading…
Reference in a new issue