Example #1
0
 public static function exceptionHandler(\Exception $exception)
 {
     $template = new Template('error.twig');
     $template->title = 'Error';
     $template->alert('danger', $exception->getMessage());
     $template->e = $exception;
     $template->render(true);
 }
Example #2
0
 public function remind(Request $request, Response $response, array $args)
 {
     $name = $request->get('name');
     if ($request->get('login')) {
         return new RedirectResponse($this->config->baseUrl() . '/login?name=' . $name);
     }
     $config = new Config();
     $user = new User($this->db);
     $user->loadByName($name);
     $template = new Template('remind_email.twig');
     if (!empty($user->getEmail())) {
         $template->user = $user;
         $template->token = $user->getReminder();
         $message = \Swift_Message::newInstance()->setSubject('Password reminder')->setFrom(array($config->siteEmail() => $config->siteTitle()))->setTo(array($user->getEmail() => $user->getName()))->setBody($template->render(), 'text/html');
         $this->email($message);
     } else {
         // Pause for a moment, so it's not so obvious which users' names are resulting in mail being sent.
         sleep(5);
     }
     $template->alert('success', 'Please check your email', true);
     return new RedirectResponse($this->config->baseUrl() . '/remind?name=' . $name);
 }
Example #3
0
 public function remindReset(Request $request, Response $response, array $args)
 {
     $template = new \App\Template('remind_reset.twig');
     // First check that the passwords match.
     $password = $request->get('password');
     if ($password !== $request->get('password-confirmation')) {
         $template->alert('warning', 'Your passwords did not match.', true);
         return new RedirectResponse($this->config->baseUrl() . "/remind/" . $args['userid'] . "/" . $args['token']);
     }
     // Then see if the token is valid.
     $user = new User($this->db);
     $user->load($args['userid']);
     if (!$user->checkReminderToken($args['token'])) {
         $template->alert('warning', 'That reminder token has expired. Please try again.', true);
         return new RedirectResponse($this->config->baseUrl() . "/remind");
     }
     // Finally change the password. This will delete the token as well.
     $user->changePassword($password);
     $template->alert('success', 'Your password has been changed. Please log in.', true);
     return new RedirectResponse($this->config->baseUrl() . "/login?name=" . $user->getName());
 }