Module: nagvis Branch: master Commit: ba5c3ac7d58de7b305f55d7d6cbe685511f56bc2 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=ba5c3ac7d58de7b305f55d7d6cbe685511f56bc2
Author: Lars Michelsen <[email protected]> Date: Tue Nov 3 21:59:44 2009 +0100 Implemented dialog/module for changing the password --- .../classes/FrontendModChangePassword.php | 117 ++++++++++++++++++++ .../nagvis-js/classes/NagVisChangePasswordView.php | 68 +++++++++++ .../templates/pages/default.changePassword.html | 22 ++++ 3 files changed, 207 insertions(+), 0 deletions(-) diff --git a/share/frontend/nagvis-js/classes/FrontendModChangePassword.php b/share/frontend/nagvis-js/classes/FrontendModChangePassword.php new file mode 100644 index 0000000..97e1425 --- /dev/null +++ b/share/frontend/nagvis-js/classes/FrontendModChangePassword.php @@ -0,0 +1,117 @@ +<?php +class FrontendModChangePassword extends FrontendModule { + protected $CORE; + protected $FHANDLER; + protected $SHANDLER; + + // Maximum length of input in forms + protected $iInputMaxLength = 15; + + public function __construct($CORE) { + $this->CORE = $CORE; + + $this->aActions = Array('view' => REQUIRES_AUTHORISATION, + 'change' => REQUIRES_AUTHORISATION); + + $this->FHANDLER = new FrontendRequestHandler($_POST); + } + + public function handleAction() { + $sReturn = ''; + + if($this->offersAction($this->sAction)) { + switch($this->sAction) { + case 'view': + // Check if user is already authenticated + if(isset($this->AUTHENTICATION) && $this->AUTHENTICATION->isAuthenticated()) { + $sReturn = $this->displayDialog(); + } else { + $sReturn = ''; + } + break; + case 'change': + // Check if user is already authenticated + if(isset($this->AUTHENTICATION) && $this->AUTHENTICATION->isAuthenticated()) { + $aReturn = $this->handleResponse(); + + $AUTH = new FrontendModAuth($this->CORE); + + if($aReturn !== false) { + $AUTH->setAction('changePassword'); + $AUTH->passNewPassword($aReturn); + + return $AUTH->handleAction(); + } else { + $sReturn = $this->msgInputNotValid(); + } + } else { + // When the user is already authenticated redirect to start page (overview) + Header('Location:'.$this->CORE->getMainCfg()->getValue('paths', 'htmlbase')); + } + break; + } + } + + return $sReturn; + } + + private function displayDialog() { + $VIEW = new NagVisChangePasswordView($this->CORE); + return json_encode(Array('code' => $VIEW->parse())); + } + + public function msgInputNotValid() { + new GlobalMessage('ERROR', $this->CORE->getLang()->getText('You entered invalid information. You will be <a href="[refererUrl]">redirected</a>.', Array('refererUrl' => $this->FHANDLER->getReferer())), null, null, 1, $this->FHANDLER->getReferer()); + + return ''; + } + + private function handleResponse() { + $bValid = true; + // Validate the response + + // Check for needed params + if($bValid && !$this->FHANDLER->isSetAndNotEmpty('passwordOld')) { + $bValid = false; + } + if($bValid && !$this->FHANDLER->isSetAndNotEmpty('passwordNew1')) { + $bValid = false; + } + if($bValid && !$this->FHANDLER->isSetAndNotEmpty('passwordNew2')) { + $bValid = false; + } + + // Check length limits + if($bValid && $this->FHANDLER->isLongerThan('passwordOld', $this->iInputMaxLength)) { + $bValid = false; + } + if($bValid && $this->FHANDLER->isLongerThan('passwordNew1', $this->iInputMaxLength)) { + $bValid = false; + } + if($bValid && $this->FHANDLER->isLongerThan('passwordNew2', $this->iInputMaxLength)) { + $bValid = false; + } + + // Check if new passwords are equal + if($bValid && $this->FHANDLER->get('passwordNew1') !== $this->FHANDLER->get('passwordNew2')) { + new GlobalMessage('ERROR', $this->CORE->getLang()->getText('The two new passwords are not equal.'), null, null, 1, $this->FHANDLER->getReferer()); + + $bValid = false; + } + + //@todo Escape vars? + + // Store response data + if($bValid === true) { + // Return the data + return Array( + 'user' => $this->AUTHENTICATION->getUser(), + 'password' => $this->FHANDLER->get('passwordOld'), + 'passwordNew' => $this->FHANDLER->get('passwordNew1')); + } else { + return false; + } + } +} + +?> diff --git a/share/frontend/nagvis-js/classes/NagVisChangePasswordView.php b/share/frontend/nagvis-js/classes/NagVisChangePasswordView.php new file mode 100644 index 0000000..bf21ff4 --- /dev/null +++ b/share/frontend/nagvis-js/classes/NagVisChangePasswordView.php @@ -0,0 +1,68 @@ +<?php +/***************************************************************************** + * + * NagVisChangePasswordView.php - Class for handling the change password page + * + * Copyright (c) 2004-2009 NagVis Project (Contact: [email protected]) + * + * License: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + *****************************************************************************/ + +/** + * @author Lars Michelsen <[email protected]> + */ +class NagVisChangePasswordView { + private $CORE; + private $iInputMaxLength = 15; + + /** + * Class Constructor + * + * @param GlobalCore $CORE + * @author Lars Michelsen <[email protected]> + */ + public function __construct($CORE) { + $this->CORE = $CORE; + } + + /** + * Parses the information in html format + * + * @return String String with Html Code + * @author Lars Michelsen <[email protected]> + */ + public function parse() { + // Initialize template system + $TMPL = New FrontendTemplateSystem($this->CORE); + $TMPLSYS = $TMPL->getTmplSys(); + + $aData = Array( + 'htmlBase' => $this->CORE->getMainCfg()->getValue('paths', 'htmlbase'), + 'formTarget' => $this->CORE->getMainCfg()->getValue('paths', 'htmlbase') . '/frontend/nagvis-js/index.php?mod=ChangePassword&act=change', + 'htmlImages' => $this->CORE->getMainCfg()->getValue('paths', 'htmlimages'), + 'maxLength' => $this->iInputMaxLength, + 'langOldPassword' => $this->CORE->getLang()->getText('Old password'), + 'langNewPassword1' => $this->CORE->getLang()->getText('New password'), + 'langNewPassword2' => $this->CORE->getLang()->getText('New password confirmation'), + 'langChangePassword' => $this->CORE->getLang()->getText('Change password') + ); + + // Build page based on the template file and the data array + return $TMPLSYS->get($TMPL->getTmplFile('changePassword'), $aData); + } +} +?> diff --git a/share/userfiles/templates/pages/default.changePassword.html b/share/userfiles/templates/pages/default.changePassword.html new file mode 100644 index 0000000..93e8854 --- /dev/null +++ b/share/userfiles/templates/pages/default.changePassword.html @@ -0,0 +1,22 @@ +<div id="changePassword"> +<form name="changePassword" id="changePasswordForm" action="{$formTarget}" method="post"> + <p> + <label>{$langOldPassword}<br /> + <input type="password" name="passwordOld" id="passwordOld" class="input" value="" size="{$maxLength}" tabindex="10" /></label> + </p> + <p> + <label>{$langNewPassword1}<br /> + <input type="password" name="passwordNew1" id="passwordNew1" class="input" value="" size="{$maxLength}" tabindex="20" /></label> + </p> + <p> + <label>{$langNewPassword2}<br /> + <input type="password" name="passwordNew2" id="passwordNew2" class="input" value="" size="{$maxLength}" tabindex="30" /></label> + </p> + <p class="submit"> + <input type="submit" name="submit" id="submit" value="{$langChangePassword}" tabindex="100" /> + </p> +</form> +</div> +<script type="text/javascript"> +try\{document.getElementById('passwordOld').focus();}catch(e)\{} +</script> ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
