summaryrefslogtreecommitdiffstats
path: root/lib/private/User
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-07-01 11:36:35 +0200
committerLukas Reschke <lukas@owncloud.com>2016-07-01 11:36:35 +0200
commit179a355b2cd3dc489a54cc27fd717f67373d0b1e (patch)
treef87a5586086635d4cbd18771b442ee771f79e441 /lib/private/User
parent8e002b61554308cb4d50570f715303a82136f0fa (diff)
parent2d2d2267f7f38ca29e7b87f40fae62261614b0d1 (diff)
downloadnextcloud-server-179a355b2cd3dc489a54cc27fd717f67373d0b1e.tar.gz
nextcloud-server-179a355b2cd3dc489a54cc27fd717f67373d0b1e.zip
Merge remote-tracking branch 'upstream/master' into master-sync-upstream
Diffstat (limited to 'lib/private/User')
-rw-r--r--lib/private/User/Session.php101
1 files changed, 61 insertions, 40 deletions
diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php
index 6219a89e5b3..dcc2e66c6c3 100644
--- a/lib/private/User/Session.php
+++ b/lib/private/User/Session.php
@@ -280,46 +280,11 @@ class Session implements IUserSession, Emitter {
*/
public function login($uid, $password) {
$this->session->regenerateId();
- if ($this->validateToken($password, $uid)) {
- // When logging in with token, the password must be decrypted first before passing to login hook
- try {
- $token = $this->tokenProvider->getToken($password);
- try {
- $loginPassword = $this->tokenProvider->getPassword($token, $password);
- $this->manager->emit('\OC\User', 'preLogin', array($uid, $loginPassword));
- } catch (PasswordlessTokenException $ex) {
- $this->manager->emit('\OC\User', 'preLogin', array($uid, ''));
- }
- } catch (InvalidTokenException $ex) {
- // Invalid token, nothing to do
- }
- $this->loginWithToken($password);
- $user = $this->getUser();
+ if ($this->validateToken($password, $uid)) {
+ return $this->loginWithToken($password);
} else {
- $this->manager->emit('\OC\User', 'preLogin', array($uid, $password));
- $user = $this->manager->checkPassword($uid, $password);
- }
- if ($user !== false) {
- if (!is_null($user)) {
- if ($user->isEnabled()) {
- $this->setUser($user);
- $this->setLoginName($uid);
- $this->manager->emit('\OC\User', 'postLogin', array($user, $password));
- if ($this->isLoggedIn()) {
- $this->prepareUserLogin();
- return true;
- } else {
- // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
- $message = \OC::$server->getL10N('lib')->t('Login canceled by app');
- throw new LoginException($message);
- }
- } else {
- // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
- $message = \OC::$server->getL10N('lib')->t('User disabled');
- throw new LoginException($message);
- }
- }
+ return $this->loginWithPassword($uid, $password);
}
return false;
}
@@ -449,6 +414,49 @@ class Session implements IUserSession, Emitter {
return false;
}
+ /**
+ * Log an user in via login name and password
+ *
+ * @param string $uid
+ * @param string $password
+ * @return boolean
+ * @throws LoginException if an app canceld the login process or the user is not enabled
+ */
+ private function loginWithPassword($uid, $password) {
+ $this->manager->emit('\OC\User', 'preLogin', array($uid, $password));
+ $user = $this->manager->checkPassword($uid, $password);
+ if ($user === false) {
+ // Password check failed
+ return false;
+ }
+
+ if ($user->isEnabled()) {
+ $this->setUser($user);
+ $this->setLoginName($uid);
+ $this->manager->emit('\OC\User', 'postLogin', array($user, $password));
+ if ($this->isLoggedIn()) {
+ $this->prepareUserLogin();
+ return true;
+ } else {
+ // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
+ $message = \OC::$server->getL10N('lib')->t('Login canceled by app');
+ throw new LoginException($message);
+ }
+ } else {
+ // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
+ $message = \OC::$server->getL10N('lib')->t('User disabled');
+ throw new LoginException($message);
+ }
+ return false;
+ }
+
+ /**
+ * Log an user in with a given token (id)
+ *
+ * @param string $token
+ * @return boolean
+ * @throws LoginException if an app canceld the login process or the user is not enabled
+ */
private function loginWithToken($token) {
try {
$dbToken = $this->tokenProvider->getToken($token);
@@ -457,12 +465,14 @@ class Session implements IUserSession, Emitter {
}
$uid = $dbToken->getUID();
+ // When logging in with token, the password must be decrypted first before passing to login hook
$password = '';
try {
$password = $this->tokenProvider->getPassword($dbToken, $token);
} catch (PasswordlessTokenException $ex) {
// Ignore and use empty string instead
}
+
$this->manager->emit('\OC\User', 'preLogin', array($uid, $password));
$user = $this->manager->get($uid);
@@ -472,13 +482,24 @@ class Session implements IUserSession, Emitter {
}
if (!$user->isEnabled()) {
// disabled users can not log in
- return false;
+ // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
+ $message = \OC::$server->getL10N('lib')->t('User disabled');
+ throw new LoginException($message);
}
//login
$this->setUser($user);
-
+ $this->setLoginName($dbToken->getLoginName());
$this->manager->emit('\OC\User', 'postLogin', array($user, $password));
+
+ if ($this->isLoggedIn()) {
+ $this->prepareUserLogin();
+ } else {
+ // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
+ $message = \OC::$server->getL10N('lib')->t('Login canceled by app');
+ throw new LoginException($message);
+ }
+
return true;
}