/** * Shows a form to create or edit a new user. */ public function treatAction() { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuUser'), array('action' => 'index'))->add($this->getTranslator()->trans('editUser'), array('action' => 'treat')); $userMapper = new UserMapper(); if ($this->getRequest()->isPost()) { $userData = $this->getRequest()->getPost('user'); if (!empty($userData['password'])) { $userData['password'] = (new PasswordService())->hash($userData['password']); } $user = $userMapper->loadFromArray($userData); if (!empty($userData['groups'])) { foreach ($userData['groups'] as $groupId) { $group = new GroupModel(); $group->setId($groupId); $user->addGroup($group); } } $date = new \Ilch\Date(); $user->setDateCreated($date); $userId = $userMapper->save($user); if (!empty($userId) && empty($userData['id'])) { $this->addMessage('newUserMsg'); } } if (empty($userId)) { $userId = $this->getRequest()->getParam('id'); } if ($userMapper->userWithIdExists($userId)) { $user = $userMapper->getUserById($userId); } else { $user = new UserModel(); } $groupMapper = new GroupMapper(); $this->getView()->set('user', $user); $this->getView()->set('groupList', $groupMapper->getGroupList()); }
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'); } } } }
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(); } } }
public function settingAction() { $profilMapper = new UserMapper(); $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuPanel'), array('controller' => 'panel', 'action' => 'index'))->add($this->getTranslator()->trans('menuSettings'), array('controller' => 'panel', 'action' => 'settings'))->add($this->getTranslator()->trans('menuSetting'), array('controller' => 'panel', 'action' => 'setting')); if ($this->getRequest()->isPost()) { $model = new UserModel(); $model->setId($this->getUser()->getId()); $model->setOptMail($this->getRequest()->getPost('opt_mail')); $profilMapper->save($model); $this->redirect(array('action' => 'setting')); } }