From 90eb09624c7ef82824669431283e121461a6799b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 2 May 2011 15:17:08 -0700 Subject: [PATCH] let users login with email address --- actions/login.php | 2 +- lib/util.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/actions/login.php b/actions/login.php index 7ec9c32139..55eccf4b2c 100644 --- a/actions/login.php +++ b/actions/login.php @@ -228,7 +228,7 @@ class LoginAction extends Action $this->elementStart('ul', 'form_data'); $this->elementStart('li'); // TRANS: Field label on login page. - $this->input('nickname', _('Nickname')); + $this->input('nickname', _('Username or email')); $this->elementEnd('li'); $this->elementStart('li'); // TRANS: Field label on login page. diff --git a/lib/util.php b/lib/util.php index f830d9b643..0b637dd1cc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -233,7 +233,13 @@ function common_check_user($nickname, $password) $authenticatedUser = false; if (Event::handle('StartCheckPassword', array($nickname, $password, &$authenticatedUser))) { - $user = User::staticGet('nickname', common_canonical_nickname($nickname)); + + if (common_is_email($nickname)) { + $user = User::staticGet('email', common_canonical_email($nickname)); + } else { + $user = User::staticGet('nickname', common_canonical_nickname($nickname)); + } + if (!empty($user)) { if (!empty($password)) { // never allow login with blank password if (0 == strcmp(common_munge_password($password, $user->id), @@ -2297,3 +2303,8 @@ function common_log_perf_counters() } } } + +function common_is_email($str) +{ + return (strpos($str, '@') !== false); +} -- 2.39.5