1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:19:59 +00:00

improved profile page user flow. clears data on success and shows current email. also, flashes success message if successful

This commit is contained in:
aldacron 2017-05-17 00:53:07 -07:00
parent c61bba8f30
commit 8ffcbca4d5
2 changed files with 15 additions and 3 deletions

View file

@ -402,7 +402,7 @@ def profile():
form = forms.ProfileForm(flask.request.form)
if flask.request.method == 'POST' and form.validate():
user = flask.g.user
new_email = form.email.data
new_email = form.email.data.strip()
new_password = form.new_password.data
if new_email:
@ -412,20 +412,26 @@ def profile():
'<strong>Email change failed!</strong> Incorrect password.'), 'danger')
return flask.redirect('/profile')
user.email = form.email.data
flask.flash(flask.Markup(
'<strong>Email successfully changed!</strong>'), 'info')
if new_password:
if form.current_password.data != user.password_hash:
flask.flash(flask.Markup(
'<strong>Password change failed!</strong> Incorrect password.'), 'danger')
return flask.redirect('/profile')
user.password_hash = form.new_password.data
flask.flash(flask.Markup(
'<strong>Password successfully changed!</strong>'), 'info')
db.session.add(user)
db.session.commit()
flask.g.user = user
return flask.redirect('/profile')
return flask.render_template('profile.html', form=form)
current_email = models.User.by_id(flask.g.user.id).email
return flask.render_template('profile.html', form=form, email=current_email)
@app.route('/user/activate/<payload>')

View file

@ -43,6 +43,12 @@
<div class="tab-pane fade" role="tabpanel" id="email-change" aria-labelledby="email-change-tab">
<form method="POST">
{{ form.csrf_token }}
<div class="row">
<div class="form-group col-md-4">
<label class="control-label" for="current_email">Current Email</label>
<div>{{email}}</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
{{ render_field(form.email, class_='form-control', placeholder='New email address') }}