Ejemplo n.º 1
0
 /**
  * try to login with the provided credentials
  *
  * @param string $uid
  * @param string $password
  * @return boolean|null
  * @throws LoginException
  */
 public function login($uid, $password)
 {
     $this->session->regenerateId();
     $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()) {
                     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;
 }
Ejemplo n.º 2
0
 /**
  * Generate a new access token clients can authenticate with
  *
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $user
  * @param string $password
  * @param string $name the name of the client
  * @return JSONResponse
  */
 public function generateToken($user, $password, $name = 'unknown client')
 {
     if (is_null($user) || is_null($password)) {
         $response = new JSONResponse();
         $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
         return $response;
     }
     $loginName = $user;
     $user = $this->userManager->checkPassword($loginName, $password);
     if ($user === false) {
         $response = new JSONResponse();
         $response->setStatus(Http::STATUS_UNAUTHORIZED);
         return $response;
     }
     if ($this->twoFactorAuthManager->isTwoFactorAuthenticated($user)) {
         $resp = new JSONResponse();
         $resp->setStatus(Http::STATUS_UNAUTHORIZED);
         return $resp;
     }
     $token = $this->secureRandom->generate(128);
     $this->tokenProvider->generateToken($token, $user->getUID(), $loginName, $password, $name, IToken::PERMANENT_TOKEN);
     return ['token' => $token];
 }
Ejemplo n.º 3
0
 /**
  * try to login with the provided credentials
  *
  * @param string $uid
  * @param string $password
  * @return bool
  */
 public function login($uid, $password)
 {
     $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));
                 return true;
             } else {
                 return false;
             }
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
	/**
	 * try to login with the provided credentials
	 *
	 * @param string $uid
	 * @param string $password
	 * @return boolean|null
	 * @throws LoginException
	 */
	public function login($uid, $password) {
		$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()) {
						return true;
					} else {
						throw new LoginException('Login canceled by app');
					}
				} else {
					return false;
				}
			}
		} else {
			return false;
		}
	}