Exemplo n.º 1
0
 /**
  * Try to sign user in
  *
  * @param string $email
  * @param string $password
  *
  * @throw Markzero\Http\Exception\ResourceNotFoundException
  *        Markzero\Auth\Exception\AuthenticationFailedException
  *        Markzero\Validation\Exception\ValidationException
  */
 public static function signIn($email, $password)
 {
     ValidationManager::validate(function ($vm) use($email, $password) {
         $vm->register('user.email', new Validator\EmailValidator($email));
         $vm->register('user.password', new Validator\RequireValidator($password), 'Password is required');
     });
     $user = User::findOneBy(['email' => $email]);
     if ($user === null) {
         throw new ResourceNotFoundException();
     }
     if (password_verify($password, $user->password_hash)) {
         self::signInWithUser($user);
     } else {
         throw new AuthenticationFailedException();
     }
 }