/**
  * @Request({"email"})
  * @Response("extension://system/views/user/reset/request.razr")
  */
 public function resetAction($email)
 {
     try {
         if ($this->user->isAuthenticated()) {
             return $this->redirect('/');
         }
         if (!$this['csrf']->validate($this['request']->request->get('_csrf'))) {
             throw new Exception(__('Invalid token. Please try again.'));
         }
         if (empty($email)) {
             throw new Exception(__('Enter a email address.'));
         }
         if (!($user = $this->users->findByEmail($email))) {
             throw new Exception(__('Invalid email address.'));
         }
         if ($user->isBlocked()) {
             throw new Exception(__('Your account has not been activated or is blocked.'));
         }
         $user->setActivation($this['auth.random']->generateString(32));
         $url = $this['url']->route('@system/resetpassword/confirm', ['user' => $user->getUsername(), 'key' => $user->getActivation()], true);
         try {
             $mail = $this['mailer']->create();
             $mail->setTo($user->getEmail())->setSubject(__('Reset password for %site%.', ['%site%' => $this['config']->get('app.site_title')]))->setBody($this['view']->render('extension://system/views/user/mails/reset.razr', compact('user', 'url', 'mail')), 'text/html')->send();
         } catch (\Exception $e) {
             throw new Exception(__('Unable to send confirmation link.'));
         }
         $this->users->save($user);
         $this['message']->success(__('Check your email for the confirmation link.'));
         return $this->redirect('/');
     } catch (Exception $e) {
         $this['message']->error($e->getMessage());
     }
     return $this->redirect('@system/resetpassword');
 }
 /**
  * @Route(methods="POST", defaults={"_maintenance"=true})
  * @Request({"redirect"})
  * @Response("extension://system/views/user/login.razr")
  */
 public function loginAction($redirect = '')
 {
     if ($this->user->isAuthenticated()) {
         $this['message']->info(__('You are already logged in.'));
         return $this->redirect('/');
     }
     return ['head.title' => __('Login'), 'last_username' => $this['session']->get(Auth::LAST_USERNAME), 'redirect' => $redirect, 'remember_me_param' => RememberMe::REMEMBER_ME_PARAM];
 }
 /**
  * {@inheritdoc}
  */
 public function updateAccess(UserInterface $user)
 {
     $this->where(['id' => $user->getId()])->update(['access' => date('Y-m-d H:i:s')]);
 }
Example #4
0
 /**
  * @param  UserInterface $user
  * @return bool
  */
 public function hasAccess(UserInterface $user)
 {
     return !($roles = $this->getRoles()) or array_intersect(array_keys($user->getRoles()), $roles);
 }