예제 #1
0
 public function newpasswordAction()
 {
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuUser'), array('controller' => 'index', 'action' => 'index'))->add($this->getTranslator()->trans('newPassword'), array('action' => 'newpassword'));
     if ($this->getRequest()->getPost('saveNewPassword')) {
         $confirmedCode = $this->getRequest()->getParam('code');
         if (empty($confirmedCode)) {
             $this->addMessage('missingConfirmedCode', 'danger');
         } else {
             $userMapper = new UserMapper();
             $user = $userMapper->getUserByConfirmedCode($confirmedCode);
             if (!empty($user)) {
                 $password = trim($this->getRequest()->getPost('password'));
                 $password2 = trim($this->getRequest()->getPost('password2'));
                 if (empty($password)) {
                     $this->addMessage('passwordEmpty', $type = 'danger');
                     $this->redirect(array('action' => 'newpassword', 'code' => $confirmedCode));
                 } elseif (empty($password2)) {
                     $this->addMessage('passwordRetypeEmpty', $type = 'danger');
                     $this->redirect(array('action' => 'newpassword', 'code' => $confirmedCode));
                 } elseif (strlen($password) < 6 or strlen($password) > 30) {
                     $this->addMessage('passwordLength', $type = 'danger');
                     $this->redirect(array('action' => 'newpassword', 'code' => $confirmedCode));
                 } elseif ($password != $password2) {
                     $this->addMessage('passwordNotEqual', $type = 'danger');
                     $this->redirect(array('action' => 'newpassword', 'code' => $confirmedCode));
                 }
                 if (!empty($password) and !empty($password2) and $password == $password2) {
                     $password = (new PasswordService())->hash($password);
                     $user->setConfirmed(1);
                     $user->setConfirmedCode('');
                     $user->setPassword($password);
                     $userMapper->save($user);
                     $this->addMessage('newPasswordSuccess');
                     $this->redirect(array('action' => 'index'));
                 }
             } else {
                 $this->addMessage('newPasswordFailed', 'danger');
             }
         }
     }
 }
예제 #2
0
 public function confirmAction()
 {
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuRegist'), array('action' => 'index'))->add($this->getTranslator()->trans('menuConfirm'), array('action' => 'confirm'));
     $errors = array();
     if ($this->getRequest()->getPost('saveConfirm')) {
         $confirmedCode = $this->getRequest()->getPost('confirmedCode');
         if (empty($confirmedCode)) {
             $errors['confirmedCode'] = 'fieldEmpty';
         }
         if (empty($errors)) {
             $this->redirect(array('controller' => 'regist', 'action' => 'confirm', 'code' => $confirmedCode));
         }
         $this->getView()->set('errors', $errors);
     } else {
         $userMapper = new UserMapper();
         $confirmed = $this->getRequest()->getParam('code');
         $user = $userMapper->getUserByConfirmedCode($confirmed);
         if (!empty($confirmed)) {
             if (!empty($user)) {
                 $currentDate = new \Ilch\Date();
                 $user->setDateConfirmed($currentDate);
                 $user->setConfirmed(1);
                 $user->setConfirmedCode('');
                 $userMapper->save($user);
                 $confirmed = '1';
                 $this->getView()->set('confirmed', $confirmed);
             } else {
                 $confirmed = null;
                 $this->getView()->set('confirmed', $confirmed);
                 $_SESSION['messages'][] = array('text' => 'Aktivierungscode Falsch', 'type' => 'warning');
             }
         } else {
             $this->getView();
         }
     }
 }