diff --git a/app/models/user.rb b/app/models/user.rb index 48bda02a6..6b1ee3d1b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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?