public function remember(UserInterface $user, Request $req, Response $res)
 {
     $cookie = new RememberMeCookie($user->email(), $req->agent());
     $this->sendRememberMeCookie($user, $cookie, $res);
     return true;
 }
 /**
  * Persists this cookie to the database.
  *
  * @param UserInterface $user
  *
  * @throws \Exception when the model cannot be saved.
  *
  * @return PersistentSession
  */
 public function persist(UserInterface $user)
 {
     $session = new PersistentSession();
     $session->email = $this->email;
     $session->series = $this->hash($this->series);
     $session->token = $this->hash($this->token);
     $session->user_id = $user->id();
     $session->two_factor_verified = $user->isTwoFactorVerified();
     try {
         $session->save();
     } catch (\Exception $e) {
         throw new \Exception("Unable to save persistent session for user # {$user->id()}: " . $e->getMessage());
     }
     return $session;
 }
 /**
  * Sends a verification email to a user.
  *
  * @param UserInterface $user
  *
  * @return bool
  */
 public function sendVerificationEmail(UserInterface $user)
 {
     $params = ['user_id' => $user->id(), 'type' => UserLink::VERIFY_EMAIL];
     // delete previous verify links
     $this->app['db']->delete('UserLinks')->where($params)->execute();
     // create new verification link
     $link = new UserLink();
     $link->create($params);
     // email it
     return $user->sendEmail('verify-email', ['verify' => $link->link]);
 }
 /**
  * Checks if a given password matches the user's password.
  *
  * @param UserInterface $user
  * @param string        $password
  *
  * @return bool
  */
 public function verifyPassword(UserInterface $user, $password)
 {
     $currentPassword = $user->getHashedPassword();
     if (!$currentPassword) {
         return false;
     }
     return hash_equals($currentPassword, $this->hash($password));
 }