File tree 3 files changed +16
-1
lines changed
3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,13 @@ class GetTokenForm(FlaskForm):
106
106
107
107
108
108
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
+ )
109
116
password = PasswordField (
110
117
_ ('New Password' ),
111
118
validators = [
Original file line number Diff line number Diff line change 6
6
{% block form_title %}{{ _('Reset Your Password') }}{% endblock %}
7
7
8
8
{% block form %}
9
+ {{ field(form.new_mail) }}
9
10
{{ field(form.password) }}
10
11
{{ field(form.confirm) }}
11
12
{{ field(form.token) }}
Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ def login():
178
178
def get_token ():
179
179
form = GetTokenForm ()
180
180
if form .validate_on_submit ():
181
- mail = form .mail .data
181
+ mail = form .mail .data . lower ()
182
182
user = find_record (User , mail = mail )
183
183
if user :
184
184
old_token_record = find_record (PasswordResetToken , user = user )
@@ -209,7 +209,14 @@ def password_reset(uid):
209
209
user = find_record (User , id = uid )
210
210
if user :
211
211
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 ))
212
217
if token_record and token_record .check_token (token ):
218
+ if new_mail :
219
+ user .mail = new_mail
213
220
user .set_password (form .password .data )
214
221
user .save ()
215
222
flash (_ ('Password reset successfully.' ), 'ok' )
You can’t perform that action at this time.
0 commit comments