From 6699a223ab0592d31b61ad970e36dc27a2702c42 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Sat, 6 Feb 2016 18:05:06 +0100 Subject: [PATCH] fix(passwordreset): Use ldap_username instead of username in form --- inside/models.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/inside/models.py b/inside/models.py index efc9fd7..7bf336a 100644 --- a/inside/models.py +++ b/inside/models.py @@ -336,7 +336,7 @@ class InsideUser(models.Model): connection_name = 'inside' cardno = models.IntegerField(unique=True, blank=True, null=True) - username = models.CharField(unique=True, max_length=12) + # username = models.CharField(unique=True, max_length=12) password = models.CharField(max_length=50) first_name = models.CharField(max_length=120, db_column='firstname') last_name = models.CharField(max_length=120, db_column='lastname') @@ -362,6 +362,16 @@ class InsideUser(models.Model): # ugly hack to use django internals for password reset last_login = datetime.datetime(2001, 1, 1) + def username(self): + """ + Django's password reset feature uses this field internally, + when we pass in a InsideUser in place of standard Django User. + + Note: The username db field is legacy, it can contain non ASCII data not suitable for *nix services. + This simply uses the ldap_username field instead, which should only contain valid usernames. + """ + return self.ldap_username + def __unicode__(self): if not self.ldap_username: return 'User {}'.format(self.pk)