* @since 1.0 * @package MammutCMS * @subpackage Module */ class MMModMuser extends MMModBase { protected function getMyId() { return 'mcms.muser'; } public function runIndex(Request $request, Response $response, $activeInstance) { $system = System::getInstance(); try { $layout = $this->findLayout($system->getSiteId(), $activeInstance); $template = $this->loadTemplate($this->getMyId(), $system->getTarget('action'), $layout); $locale = $system->getActiveLocale(); $strings = $this->loadLocaleStrings($locale, __DIR__); foreach(array( 't_login_title','t_login','t_passwd','t_remember_login','t_do_login','t_error', 't_setup','t_logout') as $id) if(isset($strings[$id])) $template->setParam($id, $strings[$id]); $template->setParam('t_title', is_null($system->getUserSvc()->getUser()) ? $strings['t_title_guest'] : $strings['t_title_user']); $template->setParam('l_setup', _SELF_ . '?mod=' . $activeInstance . '&view=settings'); $template->setParam('l_logout', _SELF_ . '?mod=' . $activeInstance . '&view=logout'); $template->setParam('self', _SELF_); $template->setParam('instance', $activeInstance); $template->setParam('isUser', !is_null($system->getUserSvc()->getUser())); $template->setParam('isSetupEnabled', bits_set($system->getUserSvc()->getUserEditOptions(), iPlugInAuth::FEATURE_UPDATE_USER)); $errors = array( -1 => 'Invalid login',-2 => 'Invalid password',-3 => 'Authentication failed'); $errors = $strings['error'] + $errors; // merge arrays without loosing keys $template->setParam('error', !empty($_REQUEST['errno']) ? $errors[$_REQUEST['errno']] : false); $response->setFragment('CONTENT', $template->getDocument()); } catch(FileNotFoundException $ex) { $response->setFragment('CONTENT', "file is missing: " . $tplfile); } } public function runLogin(Request $request, Response $response, $activeInstance) { $login = $_POST['login']; $passwd = $_POST['passwd']; $system = \MCMS\System::getInstance(); $svc = $system->getUserSvc(); $usr = $svc->loginUser($login, $passwd); $redirectParam = array(); if(!is_object($usr)) $redirectParam['errno'] = (int) $usr; $response->setRedirect($activeInstance, 'index', $redirectParam); } public function runLogout(Request $request, Response $response, $activeInstance) { $system = System::getInstance(); $svc = $system->getUserSvc(); $usr = $svc->logoutUser(); $response->setRedirect($activeInstance, 'index'); } public function runSettings(Request $request, Response $response, $activeInstance) { $system = System::getInstance(); $svc = $system->getUserSvc(); try { $layout = $this->findLayout($system->getSiteId(), $activeInstance); $template = $this->loadTemplate('mcms.muser', $system->getTarget('action'), $layout); $locale = $system->getActiveLocale(); $strings = $this->loadLocaleStrings($locale, __DIR__); foreach(array('t_setup_title','t_passwd_new','t_passwd_confirm','t_save_settings') as $id) if(isset($strings[$id])) $template->setParam($id, $strings[$id]); $template->setParam('t_title', $strings['t_setup']); $template->setParam('self', $_SERVER['PHP_SELF']); $template->setParam('logoutLink', $_SERVER['PHP_SELF'] . '?mod=' . $activeInstance . '&view=logout'); $template->setParam('instance', $activeInstance); $template->setParam('isUser', !is_null($system->getUserSvc()->getUser())); $errors = array( -1 => 'Invalid login',-2 => 'Invalid password',-3 => 'Authentication failed'); $template->setParam('error', !empty($_REQUEST['errno']) ? $errors[$_REQUEST['errno']] : false); $response->setFragment('CONTENT', $template->getDocument()); } catch(FileNotFoundException $ex) { $response->setFragment('CONTENT', "file is missing: " . $tplfile); } } public function runUpdateSettings(Request $request, Response $response, $activeInstance) { $system = System::getInstance(); $svc = $system->getUserSvc(); $param = $request->getParam(); if(is_null($system->getUserSvc()->getUser())) { $response->setRedirect($activeInstance, 'index'); return; } $result = 0; if(!empty($param['passwd1']) && $param['passwd1'] == $param['passwd2'] && strlen($param['passwd1']) >= 5) $svc->setUserPasswd($param['passwd1']); else $result = $result | 32; $response->setRedirect($activeInstance, 'settingsUpdated', array('errno' => $result)); } public function runSettingsUpdated(Request $request, Response $response, $activeInstance) { $system = System::getInstance(); $svc = $system->getUserSvc(); try { $layout = $this->findLayout($system->getSiteId(), $activeInstance); $template = $this->loadTemplate('mcms.muser', $system->getTarget('action'), $layout); $template->setParam('title', 'User'); $template->setParam('self', $_SERVER['PHP_SELF']); $template->setParam('settingLink', $_SERVER['PHP_SELF'] . '?mod=' . $activeInstance . '&view=settings'); $template->setParam('instance', $activeInstance); $template->setParam('isUser', !is_null($system->getUserSvc()->getUser())); $errors = array(32 => 'Password is to short'); $template->setParam('error', !empty($_REQUEST['errno']) ? $errors[$_REQUEST['errno']] : false); $response->setFragment('CONTENT', $template->getDocument()); } catch(FileNotFoundException $ex) { $response->setFragment('CONTENT', "file is missing: " . $tplfile); } } }