Exemplo n.º 1
0
 /**
  * Generate a new authentication code an send it to the user.
  *
  * @param TwoFactorInterface $user
  */
 public function generateAndSend(TwoFactorInterface $user)
 {
     $min = pow(10, $this->digits - 1);
     $max = pow(10, $this->digits) - 1;
     $code = $this->generateCode($min, $max);
     $user->setEmailAuthCode($code);
     $this->persister->persist($user);
     $this->mailer->sendAuthCode($user);
 }
Exemplo n.º 2
0
 /**
  * Send the auth code to the user via email.
  *
  * @param TwoFactorInterface $user
  */
 public function sendAuthCode(TwoFactorInterface $user)
 {
     $template = $this->twig->loadTemplate('WallabagUserBundle:TwoFactor:email_auth_code.html.twig');
     $subject = $template->renderBlock('subject', []);
     $bodyHtml = $template->renderBlock('body_html', ['user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl, 'wallabag_url' => $this->wallabagUrl]);
     $bodyText = $template->renderBlock('body_text', ['user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl]);
     $message = new \Swift_Message();
     $message->setTo($user->getEmail())->setFrom($this->senderEmail, $this->senderName)->setSubject($subject)->setBody($bodyText, 'text/plain')->addPart($bodyHtml, 'text/html');
     $this->mailer->send($message);
 }
 /**
  * Validates the code, which was entered by the user.
  *
  * @param TwoFactorInterface $user
  * @param int                $code
  *
  * @return bool
  */
 public function checkCode(TwoFactorInterface $user, $code)
 {
     return $user->getEmailAuthCode() == $code;
 }
Exemplo n.º 4
0
 /**
  * Send the auth code to the user via email.
  *
  * @param TwoFactorInterface $user
  */
 public function sendAuthCode(TwoFactorInterface $user)
 {
     $message = new \Swift_Message();
     $message->setTo($user->getEmail())->setFrom($this->senderEmail, $this->senderName)->setSubject('Authentication Code')->setBody($user->getEmailAuthCode());
     $this->mailer->send($message);
 }