/**
  * @NoAdminRequired
  * @NoSubadminRequired
  *
  * @return JSONResponse
  */
 public function create($name)
 {
     try {
         $sessionId = $this->session->getId();
     } catch (SessionNotAvailableException $ex) {
         $resp = new JSONResponse();
         $resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
         return $resp;
     }
     try {
         $sessionToken = $this->tokenProvider->getToken($sessionId);
         $loginName = $sessionToken->getLoginName();
         try {
             $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
         } catch (PasswordlessTokenException $ex) {
             $password = null;
         }
     } catch (InvalidTokenException $ex) {
         $resp = new JSONResponse();
         $resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
         return $resp;
     }
     $token = $this->generateRandomDeviceToken();
     $deviceToken = $this->tokenProvider->generateToken($token, $this->uid, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
     return ['token' => $token, 'deviceToken' => $deviceToken];
 }
예제 #2
0
 /**
  * Update password of the browser session token if there is one
  *
  * @param string $password
  */
 public function updateSessionTokenPassword($password)
 {
     try {
         $sessionId = $this->session->getId();
         $token = $this->tokenProvider->getToken($sessionId);
         $this->tokenProvider->setPassword($token, $sessionId, $password);
     } catch (SessionNotAvailableException $ex) {
         // Nothing to do
     } catch (InvalidTokenException $ex) {
         // Nothing to do
     }
 }
예제 #3
0
 /**
  * logout the user from the session
  */
 public function logout()
 {
     $this->manager->emit('\\OC\\User', 'logout');
     $user = $this->getUser();
     if (!is_null($user)) {
         try {
             $this->tokenProvider->invalidateToken($this->session->getId());
         } catch (SessionNotAvailableException $ex) {
         }
     }
     $this->setUser(null);
     $this->setLoginName(null);
     $this->unsetMagicInCookie();
     $this->session->clear();
 }
 /**
  * @NoAdminRequired
  * @NoSubadminRequired
  *
  * @return JSONResponse
  */
 public function create($name)
 {
     try {
         $sessionId = $this->session->getId();
     } catch (SessionNotAvailableException $ex) {
         return $this->getServiceNotAvailableResponse();
     }
     try {
         $sessionToken = $this->tokenProvider->getToken($sessionId);
         $loginName = $sessionToken->getLoginName();
         try {
             $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
         } catch (PasswordlessTokenException $ex) {
             $password = null;
         }
     } catch (InvalidTokenException $ex) {
         return $this->getServiceNotAvailableResponse();
     }
     $token = $this->generateRandomDeviceToken();
     $deviceToken = $this->tokenProvider->generateToken($token, $this->uid, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
     return ['token' => $token, 'loginName' => $loginName, 'deviceToken' => $deviceToken];
 }
예제 #5
0
 /**
  * Wrapper around session_id
  *
  * @return string
  * @throws SessionNotAvailableException
  * @since 9.1.0
  */
 public function getId()
 {
     return $this->session->getId();
 }