Skip to content

Commit 03ae422

Browse files
committed
Add interface to change email addr; fix bugs
1 parent 3c60d15 commit 03ae422

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

forms.py

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class GetTokenForm(FlaskForm):
106106

107107

108108
class PasswordResetForm(FlaskForm):
109+
new_mail = StringField(
110+
_('[Optional] New Email'),
111+
validators = [
112+
Optional(), Email(_('Invalid Email Address.'))
113+
],
114+
description = _('New email address (optional).')
115+
)
109116
password = PasswordField(
110117
_('New Password'),
111118
validators = [

templates/user/password_reset.html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{% block form_title %}{{ _('Reset Your Password') }}{% endblock %}
77

88
{% block form %}
9+
{{ field(form.new_mail) }}
910
{{ field(form.password) }}
1011
{{ field(form.confirm) }}
1112
{{ field(form.token) }}

user.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def login():
178178
def get_token():
179179
form = GetTokenForm()
180180
if form.validate_on_submit():
181-
mail = form.mail.data
181+
mail = form.mail.data.lower()
182182
user = find_record(User, mail=mail)
183183
if user:
184184
old_token_record = find_record(PasswordResetToken, user=user)
@@ -209,7 +209,14 @@ def password_reset(uid):
209209
user = find_record(User, id=uid)
210210
if user:
211211
token_record = find_record(PasswordResetToken, user=user)
212+
new_mail = form.new_mail.data.lower()
213+
if new_mail:
214+
if find_record(User, mail=new_mail):
215+
flash(_('New email address already is use.'), 'err')
216+
return redirect(url_for('.password_reset', uid=uid))
212217
if token_record and token_record.check_token(token):
218+
if new_mail:
219+
user.mail = new_mail
213220
user.set_password(form.password.data)
214221
user.save()
215222
flash(_('Password reset successfully.'), 'ok')

0 commit comments

Comments
 (0)