示例#1
0
 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Recover log in'));
     if ($this->isPostBack()) {
         $this->post->email->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $user = ModelUser::getByUsername($this->input('email'));
             if (!$user->hasRow()) {
                 $this->setMessage('No user found', 'warning');
                 response()->refresh();
             }
             if (!$this->hasErrors()) {
                 $reset = new UserReset($user->id);
                 $reset->save();
                 // TODO: Move this shit to seperate html template
                 $text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
                 $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
                 $swift = \Swift_Mailer::newInstance($transport);
                 $message = new \Swift_Message(lang('Confirm password reset on NinjaImg'));
                 $message->setFrom(env('MAIL_FROM'));
                 $message->setSender(env('MAIL_FROM'));
                 $message->setReplyTo(env('MAIL_FROM'));
                 $message->setBody($text, 'text/plain');
                 $message->setTo($user->username);
                 $swift->send($message);
                 $this->setMessage('A password reset link has been sent to your e-mail', 'success');
                 // Send mail to user confirming reset...
                 // Maybe show message with text that are active even when session disappear
                 response()->refresh();
             }
         }
     }
 }
示例#2
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'));
             }
         }
     }
 }
示例#3
0
 public function __construct()
 {
     parent::__construct();
     $user = ModelUser::getByUsername($this->input('email'));
     if (!$user->hasRow()) {
         $this->setError('Failed to confirm your account');
     } else {
         if ($user->getEmailConfirmed()) {
             $this->setMessage(lang('Your account is already confirmed.'), 'success');
         } else {
             $user->setEmailConfirmed(true);
             $user->update();
             $this->setMessage(lang('Your account has been confirmed, and you are ready to proceed with your login.'), 'success');
         }
     }
     redirect(url('user.login'));
 }
示例#4
0
 protected function inviteUser()
 {
     if ($this->input('email')) {
         if ($this->currentUser->getRole() !== UserRole::TYPE_OWNER) {
             $this->setError(lang('You dont have permissions to invite users'));
             response()->refresh();
         }
         $this->post->email->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputEmail()]);
         $this->post->role->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $user = ModelUser::getByUsername($this->input('email'));
             if ($user->hasRow() && $user->hasAccess($this->activeOrganisation->id)) {
                 if ($user->getRole() === $this->input('role')) {
                     $this->setMessage(lang('The user already has access to this organisation'), 'danger');
                 } else {
                     $user->setRole($this->input('role'));
                     $this->setMessage(lang('The role has been updated'), 'success');
                     // TODO: sent mail notifying about role-change
                 }
                 response()->refresh();
             }
             // Save invitation
             $invitation = new OrganisationInvite();
             $invitation->user_id = $this->currentUser->id;
             $invitation->email = $this->input('email');
             $invitation->organisation_id = $this->activeOrganisation->id;
             $invitation->role = $this->input('role');
             $invitation->save();
             // This point we send out a confirmation mail to accept the organisation invite.
             // TODO: move this shit to separate template
             $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
             $swift = \Swift_Mailer::newInstance($transport);
             $message = new \Swift_Message(lang('Invite to join ' . $this->activeOrganisation->name . ' on NinjaImg'));
             $message->setFrom(env('MAIL_FROM'));
             $message->setSender(env('MAIL_FROM'));
             $message->setReplyTo(env('MAIL_FROM'));
             $message->setBody("Dear customer!\n\n{$this->currentUser->data->name} has invited you to join the organisation {$this->activeOrganisation->name} on NinjaImg!\n\nClick on the link below to accept the invite:\nhttps://{$_SERVER['HTTP_HOST']}" . url('user.register') . "?email=" . $this->input('email') . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain');
             $message->setTo($this->input('email'));
             $swift->send($message);
             $this->setMessage('An invite has been sent to the user.', 'success');
         }
     }
 }