password_manager = new PasswordManager; } /** * Factory method for the lost password form * * @return Form Returns the lost password form */ public function ChangePasswordForm() { return new CustomChangePasswordForm($this, 'ChangePasswordForm'); } /** * @return string */ public function changepassword() { $tmpPage = new Page(); $tmpPage->Title = _t('Security.CHANGEPASSWORDHEADER', 'Change your password'); $tmpPage->URLSegment = 'Security'; $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children $controller = new Page_Controller($tmpPage); $controller->init(); try{ $former_hash = Session::get('AutoLoginHash'); if(!empty($former_hash)){ // Subsequent request after the "first load with hash" $customisedController = $controller->customise(array( 'Content' => '

' . _t('Security.ENTERNEWPASSWORD', 'Please enter a new password.') . '

', 'Form' => $this->ChangePasswordForm(), )); } else if(isset($_REQUEST['t']) && isset($_REQUEST['m'])){ $new_hash = $this->password_manager->verifyToken((int)@$_REQUEST['m'], @$_REQUEST['t']); Session::set('AutoLoginHash', $new_hash); return $this->redirect($this->Link('changepassword')); } else if(Member::currentUser()) { // Logged in user requested a password change form. $customisedController = $controller->customise(array( 'Content' => '

' . _t('Security.CHANGEPASSWORDBELOW', 'You can change your password below.') . '

', 'Form' => $this->ChangePasswordForm())); } else{ self::permissionFailure( $this, _t('Security.ERRORPASSWORDPERMISSION', 'You must be logged in in order to change your password!') ); return; } } catch(InvalidPasswordResetLinkException $ex1){ $customisedController = $controller->customise( array('Content' => sprintf('

This link is no longer valid as a newer request for a password reset has been made. Please check your mailbox for the most recent link

You can request a new one here', $this->Link('lostpassword')) ) ); } return $customisedController->renderWith(array('Security_changepassword', 'Security', $this->stat('template_main'), 'ContentController')); } }