diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index eb7001df..a5f40ffb 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -49,7 +49,7 @@ class SessionController extends \PHPCI\Controller } else { unset($_SESSION['login_token']); - $user = $this->userStore->getByEmail($this->getParam('email')); + $user = $this->userStore->getByLoginOrEmail($this->getParam('email')); if ($user && password_verify($this->getParam('password', ''), $user->getHash())) { session_regenerate_id(true); @@ -68,7 +68,7 @@ class SessionController extends \PHPCI\Controller $form->setAction(PHPCI_URL.'session/login'); $email = new b8\Form\Element\Email('email'); - $email->setLabel(Lang::get('email_address')); + $email->setLabel(Lang::get('login')); $email->setRequired(true); $email->setContainerClass('form-group'); $email->setClass('form-control'); diff --git a/PHPCI/Languages/lang.da.php b/PHPCI/Languages/lang.da.php index b65f9ef9..20e403e1 100644 --- a/PHPCI/Languages/lang.da.php +++ b/PHPCI/Languages/lang.da.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'PHPCI Adgangskode-nulstilling for %s', 'reset_invalid' => 'Ugyldig anmodning om adgangskode-nulstilling.', 'email_address' => 'Email-addresse', + 'login' => 'Login / Email Address', 'password' => 'Adgangskode', 'log_in' => 'Log ind', diff --git a/PHPCI/Languages/lang.de.php b/PHPCI/Languages/lang.de.php index 393459a1..8a08e37d 100644 --- a/PHPCI/Languages/lang.de.php +++ b/PHPCI/Languages/lang.de.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'PHPCI Passwort zurücksetzen für %s', 'reset_invalid' => 'Fehlerhafte Anfrage für das Zurücksetzen eines Passwortes', 'email_address' => 'Emailadresse', + 'login' => 'Login / Email Address', 'password' => 'Passwort', 'log_in' => 'Einloggen', diff --git a/PHPCI/Languages/lang.el.php b/PHPCI/Languages/lang.el.php index e97da6d3..3e3a3b84 100644 --- a/PHPCI/Languages/lang.el.php +++ b/PHPCI/Languages/lang.el.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'PHPCI Επαναφορά Κωδικού για %s', 'reset_invalid' => 'Μη έγκυρο αίτημα επαναφοράς κωδικού πρόσβασης.', 'email_address' => 'Διεύθυνση email', + 'login' => 'Login / Email Address', 'password' => 'Κωδικός πρόσβασης', 'log_in' => 'Είσοδος', diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 19d41cbe..d11a8b39 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'PHPCI Password Reset for %s', 'reset_invalid' => 'Invalid password reset request.', 'email_address' => 'Email Address', + 'login' => 'Login / Email Address', 'password' => 'Password', 'log_in' => 'Log in', diff --git a/PHPCI/Languages/lang.fr.php b/PHPCI/Languages/lang.fr.php index a8de5991..f1ad7129 100644 --- a/PHPCI/Languages/lang.fr.php +++ b/PHPCI/Languages/lang.fr.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'Réinitialisation du mot de passe PHPCI pour %s', 'reset_invalid' => 'Requête de réinitialisation de mot de passe invalide.', 'email_address' => 'Adresse email', + 'login' => 'Login / Email Address', 'password' => 'Mot de passe', 'log_in' => 'Connexion', diff --git a/PHPCI/Languages/lang.it.php b/PHPCI/Languages/lang.it.php index f8f41ea8..ff326d14 100644 --- a/PHPCI/Languages/lang.it.php +++ b/PHPCI/Languages/lang.it.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'Ripristino della password di PHPCI per %s', 'reset_invalid' => 'Richeista di ripristino password non valida.', 'email_address' => 'Indirizzo Email', + 'login' => 'Login / Email Address', 'password' => 'Password', 'log_in' => 'Accedi', diff --git a/PHPCI/Languages/lang.nl.php b/PHPCI/Languages/lang.nl.php index f3c0a7c5..e0638aaf 100644 --- a/PHPCI/Languages/lang.nl.php +++ b/PHPCI/Languages/lang.nl.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'PHPCI wachtwoord reset voor %s', 'reset_invalid' => 'Ongeldig wachtwoord reset verzoek', 'email_address' => 'E-mailadres', + 'login' => 'Login / Email Address', 'password' => 'Wachtwoord', 'log_in' => 'Log in', diff --git a/PHPCI/Languages/lang.pl.php b/PHPCI/Languages/lang.pl.php index 37a78fb6..d6f95ad6 100644 --- a/PHPCI/Languages/lang.pl.php +++ b/PHPCI/Languages/lang.pl.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'Reset Hasła PHPCI dla %s', 'reset_invalid' => 'Prośba o zmianę hasła jest nieważna.', 'email_address' => 'Adres email', + 'login' => 'Login / Email Address', 'password' => 'Hasło', 'log_in' => 'Zaloguj się', diff --git a/PHPCI/Languages/lang.ru.php b/PHPCI/Languages/lang.ru.php index 7627db85..a13c4a18 100644 --- a/PHPCI/Languages/lang.ru.php +++ b/PHPCI/Languages/lang.ru.php @@ -38,6 +38,7 @@ PHPCI', 'reset_email_title' => 'Сброс пароля PHPCI для %s', 'reset_invalid' => 'Некорректный запрос на сброс пароля.', 'email_address' => 'Email', + 'login' => 'Логин / Email', 'password' => 'Пароль', 'log_in' => 'Войти', diff --git a/PHPCI/Languages/lang.uk.php b/PHPCI/Languages/lang.uk.php index 2b2cc027..a3ca1b37 100644 --- a/PHPCI/Languages/lang.uk.php +++ b/PHPCI/Languages/lang.uk.php @@ -39,6 +39,7 @@ PHPCI', 'reset_email_title' => 'Скидання пароль PHPCI для %s', 'reset_invalid' => 'Невірний запит скидання паролю.', 'email_address' => 'Email адреса', + 'login' => 'Логин / Email адреса', 'password' => 'Пароль', 'log_in' => 'Увійти', diff --git a/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php b/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php new file mode 100644 index 00000000..f8d24ba0 --- /dev/null +++ b/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php @@ -0,0 +1,30 @@ +table('user'); + $user_table + ->addIndex('email', array('unique' => true)) + ->addIndex('name', array('unique' => true)) + ->save(); + } + + /** + * Migrate Down. + */ + public function down() + { + $user_table = $this->table('user'); + $user_table + ->removeIndex('email', array('unique' => true)) + ->removeIndex('name', array('unique' => true)) + ->save(); + } +} diff --git a/PHPCI/Store/Base/UserStoreBase.php b/PHPCI/Store/Base/UserStoreBase.php index d91271d0..f2893ac5 100644 --- a/PHPCI/Store/Base/UserStoreBase.php +++ b/PHPCI/Store/Base/UserStoreBase.php @@ -59,7 +59,7 @@ class UserStoreBase extends Store /** * Returns a User model by Email. - * @param mixed $value + * @param string $value * @param string $useConnection * @throws HttpException * @return \@appNamespace\Model\User|null @@ -82,4 +82,30 @@ class UserStoreBase extends Store return null; } + + /** + * Returns a User model by Email. + * @param string $value + * @param string $useConnection + * @throws HttpException + * @return \@appNamespace\Model\User|null + */ + public function getByLoginOrEmail($value, $useConnection = 'read') + { + if (is_null($value)) { + throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); + } + + $query = 'SELECT * FROM `user` WHERE `name` = :value OR `email` = :value LIMIT 1'; + $stmt = Database::getConnection($useConnection)->prepare($query); + $stmt->bindValue(':value', $value); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new User($data); + } + } + + return null; + } }