to login using validate with email.

This commit is contained in:
yanxd 2013-12-20 10:30:41 +08:00
parent 3f82203735
commit 7226186316
1 changed files with 7 additions and 1 deletions

View File

@ -245,6 +245,8 @@ class User < Principal
self.read_attribute(:identity_url)
end
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
# VALID_EMAIL_REGEX = /^[0-9a-zA-Z_-]+@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)+$/
# Returns the user that matches provided login and password, or nil
#登录,返回用户名与密码匹配的用户
def self.try_to_login(login, password)
@ -253,7 +255,11 @@ class User < Principal
# Make sure no one can sign in with an empty login or password
return nil if login.empty? || password.empty?
user = find_by_login(login)
if (login =~ VALID_EMAIL_REGEX)
user = find_by_mail(login)
else
user = find_by_login(login)
end
if user
# user is already in local database
#return nil unless user.active?