예제 #1
0
 public function checkUserCredentials($username, $password)
 {
     // mocking logic to throw an exception if the user is banned
     if ($username === 'banned_user') {
         $loginException = new DomainException('User is banned', 401);
         $loginException->setTitle('banned');
         $loginException->setType('http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html');
         throw $loginException;
     }
     return parent::checkUserCredentials($username, $password);
 }
예제 #2
0
 /**
  * @param $username
  * @return array|bool|null
  */
 public function getUser($username)
 {
     $cursor = $this->collection('user_table')->find([$this->identityField => $username]);
     if ($cursor->count() > 1) {
         $exception = new DomainException('Failure due to identity being ambiguous', 401);
         $exception->setType('http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html');
         $exception->setTitle('invalid_grant');
         throw $exception;
     }
     $result = null;
     foreach ($cursor as $result) {
         if ($result && isset($result['status'])) {
             if (!($result['status'] > 0)) {
                 $exception = new DomainException('User email has been not validated', 401);
                 $exception->setType('http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html');
                 $exception->setTitle('invalid_grant');
                 throw $exception;
             }
         }
     }
     return is_null($result) ? false : $result;
 }
예제 #3
0
 public function testUsesTitleFromExceptionWhenProvided()
 {
     $exception = new Exception\DomainException('exception message', 401);
     $exception->setTitle('problem title');
     $apiProblem = new ApiProblem('401', $exception);
     $payload = $apiProblem->toArray();
     $this->assertArrayHasKey('title', $payload);
     $this->assertEquals($exception->getTitle(), $payload['title']);
 }