Show More
@@ -265,7 +265,7 b' class User(Base, BaseModel):' | |||||
265 | admin = Column("admin", Boolean(), nullable=True, unique=None, default=False) |
|
265 | admin = Column("admin", Boolean(), nullable=True, unique=None, default=False) | |
266 | name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
266 | name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
267 | lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
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 | last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) |
|
269 | last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) | |
270 | ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
270 | ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
271 | api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
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 | notifications = relationship('UserNotification',) |
|
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 | @property |
|
292 | @property | |
285 | def full_name(self): |
|
293 | def full_name(self): | |
286 | return '%s %s' % (self.name, self.lastname) |
|
294 | return '%s %s' % (self.name, self.lastname) | |
@@ -324,8 +332,11 b' class User(Base, BaseModel):' | |||||
324 | return q.scalar() |
|
332 | return q.scalar() | |
325 |
|
333 | |||
326 | @classmethod |
|
334 | @classmethod | |
327 | def get_by_email(cls, email, cache=False): |
|
335 | def get_by_email(cls, email, case_insensitive=False, cache=False): | |
328 | q = cls.query().filter(cls.email == email) |
|
336 | if case_insensitive: | |
|
337 | q = cls.query().filter(cls.email.ilike(email)) | |||
|
338 | else: | |||
|
339 | q = cls.query().filter(cls.email == email) | |||
329 |
|
340 | |||
330 | if cache: |
|
341 | if cache: | |
331 | q = q.options(FromCache("sql_cache_short", |
|
342 | q = q.options(FromCache("sql_cache_short", |
@@ -396,7 +396,7 b' class ValidPerms(formencode.validators.F' | |||||
396 | class ValidSettings(formencode.validators.FancyValidator): |
|
396 | class ValidSettings(formencode.validators.FancyValidator): | |
397 |
|
397 | |||
398 | def to_python(self, value, state): |
|
398 | def to_python(self, value, state): | |
399 | #settings form can't edit user |
|
399 | # settings form can't edit user | |
400 | if value.has_key('user'): |
|
400 | if value.has_key('user'): | |
401 | del['value']['user'] |
|
401 | del['value']['user'] | |
402 |
|
402 | |||
@@ -416,7 +416,7 b' def UniqSystemEmail(old_data):' | |||||
416 | def to_python(self, value, state): |
|
416 | def to_python(self, value, state): | |
417 | value = value.lower() |
|
417 | value = value.lower() | |
418 | if old_data.get('email') != value: |
|
418 | if old_data.get('email') != value: | |
419 |
user = User. |
|
419 | user = User.get_by_email(value, case_insensitive=True) | |
420 | if user: |
|
420 | if user: | |
421 | raise formencode.Invalid( |
|
421 | raise formencode.Invalid( | |
422 | _("This e-mail address is already taken"), |
|
422 | _("This e-mail address is already taken"), | |
@@ -428,7 +428,7 b' def UniqSystemEmail(old_data):' | |||||
428 | class ValidSystemEmail(formencode.validators.FancyValidator): |
|
428 | class ValidSystemEmail(formencode.validators.FancyValidator): | |
429 | def to_python(self, value, state): |
|
429 | def to_python(self, value, state): | |
430 | value = value.lower() |
|
430 | value = value.lower() | |
431 | user = User.query().filter(User.email == value).scalar() |
|
431 | user = User.get_by_email(value, case_insensitive=True) | |
432 | if user is None: |
|
432 | if user is None: | |
433 | raise formencode.Invalid(_("This e-mail address doesn't exist.") , |
|
433 | raise formencode.Invalid(_("This e-mail address doesn't exist.") , | |
434 | value, state) |
|
434 | value, state) |
General Comments 0
You need to be logged in to leave comments.
Login now