##// END OF EJS Templates
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
marcink -
r1757:2aa7f454 beta
parent child Browse files
Show More
@@ -265,7 +265,7 b' class User(Base, BaseModel):'
265 265 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
266 266 name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
267 267 lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
268 email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
268 _email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
269 269 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
270 270 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
271 271 api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
@@ -281,6 +281,14 b' class User(Base, BaseModel):'
281 281
282 282 notifications = relationship('UserNotification',)
283 283
284 @hybrid_property
285 def email(self):
286 return self._email
287
288 @email.setter
289 def email(self, val):
290 self._email = val.lower() if val else None
291
284 292 @property
285 293 def full_name(self):
286 294 return '%s %s' % (self.name, self.lastname)
@@ -324,7 +332,10 b' class User(Base, BaseModel):'
324 332 return q.scalar()
325 333
326 334 @classmethod
327 def get_by_email(cls, email, cache=False):
335 def get_by_email(cls, email, case_insensitive=False, cache=False):
336 if case_insensitive:
337 q = cls.query().filter(cls.email.ilike(email))
338 else:
328 339 q = cls.query().filter(cls.email == email)
329 340
330 341 if cache:
@@ -416,7 +416,7 b' def UniqSystemEmail(old_data):'
416 416 def to_python(self, value, state):
417 417 value = value.lower()
418 418 if old_data.get('email') != value:
419 user = User.query().filter(User.email == value).scalar()
419 user = User.get_by_email(value, case_insensitive=True)
420 420 if user:
421 421 raise formencode.Invalid(
422 422 _("This e-mail address is already taken"),
@@ -428,7 +428,7 b' def UniqSystemEmail(old_data):'
428 428 class ValidSystemEmail(formencode.validators.FancyValidator):
429 429 def to_python(self, value, state):
430 430 value = value.lower()
431 user = User.query().filter(User.email == value).scalar()
431 user = User.get_by_email(value, case_insensitive=True)
432 432 if user is None:
433 433 raise formencode.Invalid(_("This e-mail address doesn't exist.") ,
434 434 value, state)
General Comments 0
You need to be logged in to leave comments. Login now