|
|
@@ -41,6 +41,7 @@ use OC\Authentication\Exceptions\PasswordLoginForbiddenException; |
|
|
|
use OC\Authentication\Token\IProvider; |
|
|
|
use OC\Authentication\Token\IToken; |
|
|
|
use OC\Hooks\Emitter; |
|
|
|
use OC\Hooks\PublicEmitter; |
|
|
|
use OC_User; |
|
|
|
use OC_Util; |
|
|
|
use OCA\DAV\Connector\Sabre\Auth; |
|
|
@@ -78,7 +79,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; |
|
|
|
*/ |
|
|
|
class Session implements IUserSession, Emitter { |
|
|
|
|
|
|
|
/** @var IUserManager $manager */ |
|
|
|
/** @var IUserManager|PublicEmitter $manager */ |
|
|
|
private $manager; |
|
|
|
|
|
|
|
/** @var ISession $session */ |
|
|
@@ -156,7 +157,7 @@ class Session implements IUserSession, Emitter { |
|
|
|
/** |
|
|
|
* get the manager object |
|
|
|
* |
|
|
|
* @return Manager |
|
|
|
* @return Manager|PublicEmitter |
|
|
|
*/ |
|
|
|
public function getManager() { |
|
|
|
return $this->manager; |
|
|
@@ -324,6 +325,41 @@ class Session implements IUserSession, Emitter { |
|
|
|
return $this->loginWithPassword($uid, $password); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param IUser $user |
|
|
|
* @param array $loginDetails |
|
|
|
* @return bool |
|
|
|
* @throws LoginException |
|
|
|
*/ |
|
|
|
public function completeLogin(IUser $user, array $loginDetails) { |
|
|
|
if (!$user->isEnabled()) { |
|
|
|
// disabled users can not log in |
|
|
|
// 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); |
|
|
|
} |
|
|
|
|
|
|
|
$this->setUser($user); |
|
|
|
$this->setLoginName($loginDetails['loginName']); |
|
|
|
|
|
|
|
if(isset($loginDetails['token']) && $loginDetails['token'] instanceof IToken) { |
|
|
|
$this->setToken($loginDetails['token']->getId()); |
|
|
|
\OC::$server->getLockdownManager()->setToken($loginDetails['token']); |
|
|
|
$firstTimeLogin = false; |
|
|
|
} else { |
|
|
|
$this->setToken(null); |
|
|
|
$firstTimeLogin = $user->updateLastLoginTimestamp(); |
|
|
|
} |
|
|
|
$this->manager->emit('\OC\User', 'postLogin', [$user, $loginDetails['password']]); |
|
|
|
if($this->isLoggedIn()) { |
|
|
|
$this->prepareUserLogin($firstTimeLogin); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
$message = \OC::$server->getL10N('lib')->t('Login canceled by app'); |
|
|
|
throw new LoginException($message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Tries to log in a client |
|
|
|
* |
|
|
@@ -498,25 +534,7 @@ class Session implements IUserSession, Emitter { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if ($user->isEnabled()) { |
|
|
|
$this->setUser($user); |
|
|
|
$this->setLoginName($uid); |
|
|
|
$this->setToken(null); |
|
|
|
$firstTimeLogin = $user->updateLastLoginTimestamp(); |
|
|
|
$this->manager->emit('\OC\User', 'postLogin', [$user, $password]); |
|
|
|
if ($this->isLoggedIn()) { |
|
|
|
$this->prepareUserLogin($firstTimeLogin); |
|
|
|
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->completeLogin($user, ['loginName' => $uid, 'password' => $password]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -547,29 +565,8 @@ class Session implements IUserSession, Emitter { |
|
|
|
// user does not exist |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!$user->isEnabled()) { |
|
|
|
// disabled users can not log in |
|
|
|
// 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->setToken($dbToken->getId()); |
|
|
|
$this->lockdownManager->setToken($dbToken); |
|
|
|
$this->manager->emit('\OC\User', 'postLogin', array($user, $password)); |
|
|
|
|
|
|
|
if ($this->isLoggedIn()) { |
|
|
|
$this->prepareUserLogin(false); // token login cant be the first |
|
|
|
} 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; |
|
|
|
return $this->completeLogin($user, ['loginName' => $uid, 'password' => $password, 'token' => $dbToken]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |