From 72261863167918c3d2eb9b36781bfb15b173425f Mon Sep 17 00:00:00 2001 From: yanxd Date: Fri, 20 Dec 2013 10:30:41 +0800 Subject: [PATCH] to login using validate with email. --- app/models/user.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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?