Allow login by email address

This commit is contained in:
Thomas Müller 2016-05-02 14:51:01 +02:00
parent b10dcfc3b7
commit 7aca13f14c
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
2 changed files with 13 additions and 5 deletions

View File

@ -40,11 +40,11 @@ script('core', [
</div> </div>
<p class="grouptop"> <p class="grouptop">
<input type="text" name="user" id="user" <input type="text" name="user" id="user"
placeholder="<?php p($l->t('Username')); ?>" placeholder="<?php p($l->t('Username or email')); ?>"
value="<?php p($_['loginName']); ?>" value="<?php p($_['loginName']); ?>"
<?php p($_['user_autofocus'] ? 'autofocus' : ''); ?> <?php p($_['user_autofocus'] ? 'autofocus' : ''); ?>
autocomplete="on" autocapitalize="off" autocorrect="off" required> autocomplete="on" autocapitalize="off" autocorrect="off" required>
<label for="user" class="infield"><?php p($l->t('Username')); ?></label> <label for="user" class="infield"><?php p($l->t('Username or email')); ?></label>
</p> </p>
<p class="groupbottom"> <p class="groupbottom">

View File

@ -152,14 +152,22 @@ class OC_User {
/** /**
* Try to login a user * Try to login a user
* *
* @param string $loginname The login name of the user to log in * @param string $loginName The login name of the user to log in
* @param string $password The password of the user * @param string $password The password of the user
* @return boolean|null * @return boolean|null
* *
* Log in a user and regenerate a new session - if the password is ok * Log in a user and regenerate a new session - if the password is ok
*/ */
public static function login($loginname, $password) { public static function login($loginName, $password) {
$result = self::getUserSession()->login($loginname, $password);
$result = self::getUserSession()->login($loginName, $password);
if (!$result) {
$users = \OC::$server->getUserManager()->getByEmail($loginName);
// we only allow login by email if unique
if (count($users) === 1) {
$result = self::getUserSession()->login($users[0]->getUID(), $password);
}
}
if ($result) { if ($result) {
// Refresh the token // Refresh the token
\OC::$server->getCsrfTokenManager()->refreshToken(); \OC::$server->getCsrfTokenManager()->refreshToken();