20
20
UserModel = get_user_model ()
21
21
22
22
23
+ def _unicode_ci_compare (s1 , s2 ):
24
+ """
25
+ Perform case-insensitive comparison of two identifiers, using the
26
+ recommended algorithm from Unicode Technical Report 36, section
27
+ 2.11.2(B)(2).
28
+ """
29
+ return unicodedata .normalize ('NFKC' , s1 ).casefold () == unicodedata .normalize ('NFKC' , s2 ).casefold ()
30
+
31
+
23
32
class ReadOnlyPasswordHashWidget (forms .Widget ):
24
33
template_name = 'auth/widgets/read_only_password_hash.html'
25
34
read_only = True
@@ -269,11 +278,16 @@ def get_users(self, email):
269
278
that prevent inactive users and users with unusable passwords from
270
279
resetting their password.
271
280
"""
281
+ email_field_name = UserModel .get_email_field_name ()
272
282
active_users = UserModel ._default_manager .filter (** {
273
- '%s__iexact' % UserModel . get_email_field_name () : email ,
283
+ '%s__iexact' % email_field_name : email ,
274
284
'is_active' : True ,
275
285
})
276
- return (u for u in active_users if u .has_usable_password ())
286
+ return (
287
+ u for u in active_users
288
+ if u .has_usable_password () and
289
+ _unicode_ci_compare (email , getattr (u , email_field_name ))
290
+ )
277
291
278
292
def save (self , domain_override = None ,
279
293
subject_template_name = 'registration/password_reset_subject.txt' ,
@@ -286,15 +300,17 @@ def save(self, domain_override=None,
286
300
user.
287
301
"""
288
302
email = self .cleaned_data ["email" ]
303
+ email_field_name = UserModel .get_email_field_name ()
289
304
for user in self .get_users (email ):
290
305
if not domain_override :
291
306
current_site = get_current_site (request )
292
307
site_name = current_site .name
293
308
domain = current_site .domain
294
309
else :
295
310
site_name = domain = domain_override
311
+ user_email = getattr (user , email_field_name )
296
312
context = {
297
- 'email' : email ,
313
+ 'email' : user_email ,
298
314
'domain' : domain ,
299
315
'site_name' : site_name ,
300
316
'uid' : urlsafe_base64_encode (force_bytes (user .pk )),
@@ -305,7 +321,7 @@ def save(self, domain_override=None,
305
321
}
306
322
self .send_mail (
307
323
subject_template_name , email_template_name , context , from_email ,
308
- email , html_email_template_name = html_email_template_name ,
324
+ user_email , html_email_template_name = html_email_template_name ,
309
325
)
310
326
311
327
0 commit comments