コード例 #1
0
ファイル: Api.php プロジェクト: CPDeutschland/zf2-api-client
 /**
  * Performs an authentication attempt
  *
  * @return \Zend\Authentication\Result
  * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface
  *               If authentication cannot be performed
  */
 public function authenticate()
 {
     $result = ApiClient::authenticate(array('username' => $this->username, 'password' => $this->password));
     if ($result['result'] === true) {
         $hydrator = new ClassMethods();
         $user = $hydrator->hydrate(ApiClient::getUser($this->username), new User());
         $response = new Result(Result::SUCCESS, $user, array('Authentication successful.'));
     } else {
         $response = new Result(Result::FAILURE, NULL, array('Invalid credentials.'));
     }
     return $response;
 }
コード例 #2
0
ファイル: Api.php プロジェクト: CPDeutschland/zf2-api-client
 /**
  * Performs an authentication attempt
  *
  * @return \Zend\Authentication\Result
  * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface
  *               If authentication cannot be performed
  */
 public function authenticate()
 {
     $result = ApiClient::authenticate(array('username' => $this->username, 'password' => $this->password));
     if (array_key_exists('access_token', $result) && !empty($result['access_token'])) {
         $hydrator = new ClassMethods();
         $user = $hydrator->hydrate(ApiClient::getUser($this->username), new User());
         $session = new Container('oauth_session');
         $session->setExpirationSeconds($result['expires_in']);
         $session->accessToken = $result['access_token'];
         $response = new Result(Result::SUCCESS, $user, array('Authentication successful.'));
     } else {
         $response = new Result(Result::FAILURE, NULL, array('Invalid credentials.'));
     }
     return $response;
 }