Пример #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'));
             }
         }
     }
 }
Пример #2
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();
             }
         }
     }
 }
Пример #3
0
 public function __construct()
 {
     parent::__construct();
     // Extending this class requires the user to be authenticated
     if (!ModelUser::isLoggedIn()) {
         $this->setMessage('This page can only be viewed when logged in', 'warning', 'main');
         redirect(url('user.login'), 301);
     }
     $this->currentUser = ModelUser::current(true);
     $this->getSite()->addWrappedCss('bootstrap.css');
     $this->getSite()->addWrappedCss('bootstrap-theme.css');
     $this->getSite()->addWrappedCss('starter-template.css');
     $this->getSite()->addWrappedJs('jquery.min.js');
     $this->getSite()->addWrappedJs('global.js');
     $this->sidemenu = new Menu();
     $this->sidemenu->addItem(lang('Sources'), url('controlpanel.source'));
     $this->sidemenu->addItem(lang('Invoices'), url('controlpanel.invoices'));
     $this->sidemenu->addItem(lang('Payment'), url('controlpanel.payment'));
     $this->sidemenu->addItem(lang('Account'), url('controlpanel.account'));
     //$this->sidemenu->addItem(lang('Statistics'), url('controlpanel.statistic'));
     $this->mainMenu->addItem(lang('Organisations'), url('controlpanel.organisations'));
     if ($this->currentUser->admin_level > 0) {
         $this->mainMenu->addItem(lang('Admin'), url('admin.home'));
     }
     $this->mainMenu->addItem(lang('Sign out'), url('user.signout'));
     $this->setTemplate('Controlpanel.php');
     $this->activeOrganisation = request()->organisation;
 }
Пример #4
0
 public function __construct($key)
 {
     parent::__construct();
     $newPassword = uniqid();
     $reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword);
     if ($reset) {
         $user = ModelUser::getById($reset);
         if ($user->hasRow()) {
             // Send mail with new password
             // TODO: Move this shit to separate html template
             $user->setEmailConfirmed(true);
             $user->update();
             $text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: "******"\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('New password for 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 new password has been sent to your e-mail.', 'success');
             redirect(url('user.login'));
         }
         redirect(url('home'));
     }
 }
Пример #5
0
function mailAdmins($subject, $text)
{
    $admins = \NinjaImg\Model\ModelUser::get(null, 1);
    if ($admins->hasRows()) {
        foreach ($admins as $admin) {
            sendMail($admin->username, $subject, $text);
        }
    }
}
Пример #6
0
 public static function getUsers($organisationId)
 {
     $ids = array();
     $tmpIds = Pdo::getInstance()->all('SELECT `user_id` FROM `user_organisation` WHERE `organisation_id` = ?', [$organisationId]);
     foreach ($tmpIds as $id) {
         $ids[] = $id->user_id;
     }
     return ModelUser::getByIds($ids);
 }
Пример #7
0
 public function __construct()
 {
     parent::__construct();
     // Extending this class requires the user to be authenticated
     if (!ModelUser::isLoggedIn()) {
         $this->setMessage('This page can only be viewed when logged in', 'warning', 'main');
         redirect(url('home'), 301);
     }
     $this->currentUser = ModelUser::current();
 }
Пример #8
0
 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Administration'));
     // Extending this class requires the user to be authenticated
     if (!ModelUser::isLoggedIn() || ModelUser::isLoggedIn() && ModelUser::current()->admin_level < 1) {
         $this->setMessage('You need special permissions to view this page', 'warning', 'main');
         redirect(url('user.login'), 301);
     }
     $this->sidemenu = new Menu();
     $this->sidemenu->addItem(lang('Home'), url('admin.home'));
     $this->sidemenu->addItem(lang('Payments'), url('admin.payment'));
     $this->sidemenu->addItem(lang('Settings'), url('admin.settings'));
 }
Пример #9
0
 public function handle(Request $request)
 {
     $this->request = $request;
     // Extending this class requires the user to be authenticated
     if (!ModelUser::isLoggedIn()) {
         $this->setMessage('This page can only be viewed when logged in', 'warning', 'main');
         redirect(url('home'), 301);
     }
     $this->request->user = ModelUser::current();
     $this->validateOrganisation();
     if ($this->request->user->getActiveOrganisation()) {
         $this->request->organisation = ModelOrganisation::getById($this->request->user->getActiveOrganisation());
     }
 }
Пример #10
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'));
 }
Пример #11
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');
         }
     }
 }
Пример #12
0
 protected function sendCustomerMail(OrganisationInvoice $invoice)
 {
     $users = ModelUser::getByOrganisationId($this->organisation->id, UserRole::TYPE_OWNER);
     if ($users->hasRows()) {
         foreach ($users as $user) {
             $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
             $swift = \Swift_Mailer::newInstance($transport);
             $message = new \Swift_Message(lang('New invoice available for ' . $this->organisation->name));
             $currency = ModelSettings::getInstance()->data->default_currency_character;
             $message->setFrom(env('MAIL_FROM'));
             $message->setSender(env('MAIL_FROM'));
             $message->setReplyTo(env('MAIL_FROM'));
             $message->setBody("Dear {$user->data->name}!\n\nAttached is the latest invoice from NinjaImg.\n\nThe amount for invoice {$invoice->invoice_id} is {$invoice->amount_total}{$currency} with payment date {$invoice->due_date}.\n\nYou can always view your invoices at your controlpanel on ninjaimg.com.\n\nThanks for supporting our service, we really appreciate it!\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain');
             $message->setTo($user->username);
             $attachment = new \Swift_Attachment(file_get_contents($invoice->path), basename($invoice->path), File::getMime($invoice->path));
             $message->attach($attachment);
             $swift->send($message);
         }
     }
 }
Пример #13
0
 protected function invitationAcceptedMail(OrganisationInvite $invite, ModelOrganisation $organisation, ModelUser $user)
 {
     $senderUser = ModelUser::getById($invite->user_id);
     if ($senderUser->hasRow() && !$senderUser->deleted) {
         $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
         $swift = \Swift_Mailer::newInstance($transport);
         $message = new \Swift_Message(lang('Invitation to ' . $organisation->name . ' accepted'));
         $message->setFrom(env('MAIL_FROM'));
         $message->setSender(env('MAIL_FROM'));
         $message->setReplyTo(env('MAIL_FROM'));
         $message->setBody("Dear {$senderUser->data->name}!\n\nWe are writing to inform you, that {$user->data->name} has just accepted your invitation to join the organisation {$organisation->name} on NinjaImg.\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain');
         $message->setTo($senderUser->username);
         $swift->send($message);
     }
 }
Пример #14
0
 protected function requireAuth()
 {
     if (!ModelUser::IsLoggedIn()) {
         $this->redirect(url('user.login'));
     }
 }