예제 #1
0
 /**
  * Performs the Login for a User
  * @param string $userNameOrEmail
  * @param string $password
  * @return LoginResult
  */
 public function perform($userNameOrEmail, $password)
 {
     $user = $this->mapper->getUserByEmail($userNameOrEmail);
     if ($user == null) {
         $user = $this->mapper->getUserByName($userNameOrEmail);
     }
     if ($user == null || !$this->passwordService->verify($password, $user->getPassword())) {
         return new LoginResult(false, $user, LoginResult::LOGIN_FAILED);
     } elseif (!$user->getConfirmed()) {
         return new LoginResult(false, $user, LoginResult::USER_NOT_ACTIVATED);
     }
     $_SESSION['user_id'] = $user->getId();
     return new LoginResult(true, $user);
 }
예제 #2
0
 public function inputAction()
 {
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuRegist'), array('action' => 'index'))->add($this->getTranslator()->trans('step2to3'), array('action' => 'input'));
     $registMapper = new UserMapper();
     $errors = array();
     if ($this->getRequest()->getPost('saveRegist')) {
         $name = $this->getRequest()->getPost('name');
         $password = $this->getRequest()->getPost('password');
         $password2 = $this->getRequest()->getPost('password2');
         $email = trim($this->getRequest()->getPost('email'));
         $captcha = trim(strtolower($this->getRequest()->getPost('captcha')));
         $profilName = $registMapper->getUserByName($name);
         $profilEmail = $registMapper->getUserByEmail($email);
         if (empty($_SESSION['captcha']) || $captcha != $_SESSION['captcha']) {
             $errors['captcha'] = 'invalidCaptcha';
         }
         if (!empty($profilName)) {
             $errors['name'] = 'nameExist';
         }
         if (!empty($profilEmail)) {
             $errors['email'] = 'emailExist';
         }
         if (empty($name)) {
             $errors['name'] = 'fieldEmpty';
         }
         if (empty($password)) {
             $errors['password'] = '******';
         }
         if (empty($password2)) {
             $errors['password2'] = 'fieldEmpty';
         }
         if ($password !== $password2) {
             $errors['password'] = '******';
             $errors['password2'] = 'fieldDiffersPassword';
         }
         if (empty($email)) {
             $errors['email'] = 'fieldEmpty';
         } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $errors['email'] = 'fieldEmail';
         }
         if (empty($errors)) {
             $groupMapper = new \Modules\User\Mappers\Group();
             $userGroup = $groupMapper->getGroupById(2);
             $currentDate = new \Ilch\Date();
             $model = new \Modules\User\Models\User();
             $model->setName($name);
             $model->setPassword((new PasswordService())->hash($password));
             $model->setEmail($email);
             $model->setDateCreated($currentDate);
             $model->addGroup($userGroup);
             if ($this->getConfig()->get('regist_confirm') == 0) {
                 $model->setDateConfirmed($currentDate);
             } else {
                 $confirmedCode = md5(uniqid(rand()));
                 $model->setConfirmed(0);
                 $model->setConfirmedCode($confirmedCode);
             }
             $registMapper->save($model);
             $_SESSION["name"] = $name;
             $_SESSION["email"] = $email;
             if ($this->getConfig()->get('regist_confirm') == 1) {
                 $sitetitle = $this->getConfig()->get('page_title');
                 $confirmCode = '<a href="' . BASE_URL . '/index.php/user/regist/confirm/code/' . $confirmedCode . '" class="btn btn-primary btn-sm">' . $this->getTranslator()->trans('confirmMailButtonText') . '</a>';
                 $date = new \Ilch\Date();
                 $layout = '';
                 if (isset($_SESSION['layout'])) {
                     $layout = $_SESSION['layout'];
                 }
                 if ($layout == $this->getConfig()->get('default_layout') && file_exists(APPLICATION_PATH . '/layouts/' . $this->getConfig()->get('default_layout') . '/views/modules/user/layouts/mail/registconfirm.php')) {
                     $messageTemplate = file_get_contents(APPLICATION_PATH . '/layouts/' . $this->getConfig()->get('default_layout') . '/views/modules/user/layouts/mail/registconfirm.php');
                 } else {
                     $messageTemplate = file_get_contents(APPLICATION_PATH . '/modules/user/layouts/mail/registconfirm.php');
                 }
                 $messageReplace = array('{content}' => $this->getConfig()->get('regist_confirm_mail'), '{sitetitle}' => $sitetitle, '{date}' => $date->format("l, d. F Y", true), '{name}' => $name, '{confirm}' => $confirmCode, '{footer}' => $this->getTranslator()->trans('noReplyMailFooter'));
                 $message = str_replace(array_keys($messageReplace), array_values($messageReplace), $messageTemplate);
                 $mail = new \Ilch\Mail();
                 $mail->setTo($email, $name)->setSubject($this->getTranslator()->trans('automaticEmail'))->setFrom($this->getTranslator()->trans('automaticEmail'), $sitetitle)->setMessage($message)->addGeneralHeader('Content-type', 'text/html; charset="utf-8"');
                 $mail->send();
             }
             $this->redirect(array('action' => 'finish'));
         }
         $this->getView()->set('errors', $errors);
     }
     $this->getView();
 }
예제 #3
0
 public function forgotpasswordAction()
 {
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuLogin'), array('action' => 'index'))->add($this->getTranslator()->trans('menuForgotPassword'), array('action' => 'forgotpassword'));
     if ($this->getRequest()->getPost('saveNewPassword')) {
         $name = trim($this->getRequest()->getPost('name'));
         if (empty($name)) {
             $this->addMessage('missingNameEmail', 'danger');
         } else {
             $userMapper = new UserMapper();
             $user = $userMapper->getUserByEmail($name);
             if ($user == null) {
                 $user = $userMapper->getUserByName($name);
             }
             if (!empty($user)) {
                 $confirmedCode = md5(uniqid(rand()));
                 $user->setConfirmed(0);
                 $user->setConfirmedCode($confirmedCode);
                 $userMapper->save($user);
                 $name = $user->getName();
                 $email = $user->getEmail();
                 $sitetitle = $this->getConfig()->get('page_title');
                 $confirmCode = '<a href="' . BASE_URL . '/index.php/user/login/newpassword/code/' . $confirmedCode . '" class="btn btn-primary btn-sm">' . $this->getTranslator()->trans('confirmMailButtonText') . '</a>';
                 $date = new \Ilch\Date();
                 if ($_SESSION['layout'] == $this->getConfig()->get('default_layout') && file_exists(APPLICATION_PATH . '/layouts/' . $this->getConfig()->get('default_layout') . '/views/modules/user/layouts/mail/passwordchange.php')) {
                     $messageTemplate = file_get_contents(APPLICATION_PATH . '/layouts/' . $this->getConfig()->get('default_layout') . '/views/modules/user/layouts/mail/passwordchange.php');
                 } else {
                     $messageTemplate = file_get_contents(APPLICATION_PATH . '/modules/user/layouts/mail/passwordchange.php');
                 }
                 $messageReplace = array('{content}' => $this->getConfig()->get('password_change_mail'), '{sitetitle}' => $sitetitle, '{date}' => $date->format("l, d. F Y", true), '{name}' => $name, '{confirm}' => $confirmCode, '{footer}' => $this->getTranslator()->trans('noReplyMailFooter'));
                 $message = str_replace(array_keys($messageReplace), array_values($messageReplace), $messageTemplate);
                 $mail = new \Ilch\Mail();
                 $mail->setTo($email, $name)->setSubject($this->getTranslator()->trans('automaticEmail'))->setFrom($this->getTranslator()->trans('automaticEmail'), $sitetitle)->setMessage($message)->addGeneralHeader('Content-type', 'text/html; charset="utf-8"');
                 $mail->send();
                 $this->addMessage('newPasswordEMailSuccess');
             } else {
                 $this->addMessage('newPasswordFailed', 'danger');
             }
         }
     }
 }