Exemplo n.º 1
0
 /**
  * Attempt to return a Reply for the authenticated user.
  * @param \Fluxoft\Rebar\Http\Request $request
  * @return Reply
  */
 public function GetAuthenticatedUser(Request $request)
 {
     if (!isset($this->auth)) {
         $auth = new Reply();
         $authUser = null;
         // Check that valid tokens are set
         $validToken = $this->getValidTokenPayload($request);
         if (!isset($validToken)) {
             $auth->Message = 'No valid AuthToken found in Request.';
         } else {
             if ($validToken === 'expired') {
                 $auth->Message = 'The token is expired.';
             } else {
                 // a valid token was found - use it to pull the correct user
                 $authUser = $this->userMapper->GetAuthorizedUserById($validToken->userID);
                 if ($authUser instanceof UserInterface) {
                     $tokenString = $this->getTokenString($authUser);
                     $auth->Auth = true;
                     $auth->Token = $tokenString;
                     $auth->Message = 'Found valid token and logged in';
                     $auth->Message = $validToken;
                 } else {
                     $auth->Message = 'Tried to log in using token but user not found.';
                 }
             }
         }
         $auth->User = $authUser;
         $this->auth = $auth;
     }
     return $this->auth;
 }
Exemplo n.º 2
0
 /**
  * Attempt to return a Reply for the authenticated user.
  * @param Request $request
  * @return Reply
  */
 public function GetAuthenticatedUser(Request $request)
 {
     if (!isset($this->auth)) {
         $auth = new Reply();
         $userID = $this->session->Get('AuthUserID', null);
         $authUser = null;
         if (!isset($userID)) {
             // Check that valid tokens are set
             $validToken = $this->getValidToken($request);
             if ($validToken === false) {
                 // kill any remaining cookies or sessions in this case
                 $this->cookies->Delete('AuthToken');
                 $this->session->Delete('AuthUserID');
                 $this->session->Delete('AuthToken');
             } else {
                 // a valid token was found - use it to pull the correct user
                 $authUser = $this->userMapper->GetAuthorizedUserById($validToken->UserID);
                 if ($authUser instanceof UserInterface) {
                     $tokenString = $this->setTokens($authUser, $validToken);
                     $auth->Auth = true;
                     $auth->Token = $tokenString;
                     $auth->Message = 'Found valid token.';
                 } else {
                     $auth->Message = 'Tried to log in using token but user not found. ' . $validToken->UserID;
                 }
             }
         } else {
             // the user ID was found in the session, use that to log in
             $authUser = $this->userMapper->GetAuthorizedUserById($userID);
             if ($authUser instanceof UserInterface) {
                 $auth->Auth = true;
                 $auth->Token = $this->session->Get('AuthToken');
                 $auth->Message = 'Logged in using session';
             } else {
                 $auth->Message = 'Tried to log in with session but user not found';
             }
         }
         $auth->User = $authUser;
         $this->auth = $auth;
     }
     return $this->auth;
 }