Exemplo n.º 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);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  * @param array $errors [optional]
  */
 public function __construct($message = null, $code = null, Exception $previous = null, array $errors = null)
 {
     if (!empty($errors)) {
         $this->setAdditionalDetails(array('errors' => $errors));
     }
     parent::__construct($message, $code, $previous);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 public function testUsesAdditionalDetailsFromExceptionWhenProvided()
 {
     $exception = new Exception\DomainException('exception message', 401);
     $exception->setAdditionalDetails(['foo' => 'bar']);
     $apiProblem = new ApiProblem('401', $exception);
     $payload = $apiProblem->toArray();
     $this->assertArrayHasKey('foo', $payload);
     $this->assertEquals('bar', $payload['foo']);
 }