示例#1
0
 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Log in'));
     if (ModelUser::isLoggedIn()) {
         $this->setMessage(lang('Welcome back ' . ModelUser::current()->data->name), 'success', 'main');
         redirect(url('controlpanel.home'));
     }
     if ($this->isPostBack()) {
         $this->post->email->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputEmail()]);
         if (!$this->hasErrors()) {
             try {
                 $user = ModelUser::getByUsername($this->input('email'));
                 if ($user->hasRow() && !$user->getEmailConfirmed()) {
                     $this->setError(lang('Please confirm your e-mail.'));
                     response()->refresh();
                 }
                 ModelUser::authenticate($this->input('email'), $this->input('password'));
             } catch (UserException $e) {
                 $this->setError($e->getMessage());
             }
             if (!$this->hasErrors()) {
                 redirect(url('controlpanel.organisations'));
             }
         }
     }
 }