[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * $Horde: horde/services/resetpassword.php,v 1.5.10.7 2006/05/24 22:45:13 chuck Exp $ 4 * 5 * Copyright 2004-2006 Marko Djukic <marko@oblo.com> 6 * 7 * See the enclosed file COPYING for license information (LGPL). If you 8 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 9 */ 10 11 @define('AUTH_HANDLER', true); 12 @define('HORDE_BASE', dirname(__FILE__) . '/..'); 13 require_once HORDE_BASE . '/lib/base.php'; 14 require_once 'Horde/Form.php'; 15 require_once 'Horde/String.php'; 16 require_once 'Horde/Variables.php'; 17 18 // Make sure auth backend allows passwords to be reset. 19 $auth = &Auth::singleton($conf['auth']['driver']); 20 if (!$auth->hasCapability('resetpassword')) { 21 $notification->push(_("Cannot reset password automatically, contact your administrator."), 'horde.error'); 22 header('Location: ' . Auth::getLoginScreen('', Util::getFormData('url'))); 23 exit; 24 } 25 26 $vars = &Variables::getDefaultVariables(); 27 28 $title = _("Reset Your Password"); 29 $form = &Horde_Form::singleton('HordeSignupForm', $vars, $title); 30 $form->setButtons(_("Continue")); 31 32 /* Set up the fields for the username and alternate email. */ 33 $form->addHidden('', 'url', 'text', false); 34 $v = &$form->addVariable(_("Username"), 'username', 'text', true); 35 $v->setOption('trackchange', true); 36 $form->addVariable(_("Alternate email address"), 'email', 'email', true); 37 $can_validate = false; 38 39 /* If a username has been supplied try fetching the prefs stored info. */ 40 if ($username = $vars->get('username')) { 41 $username = Auth::addHook($username); 42 $prefs = &Prefs::singleton($conf['prefs']['driver'], 'horde', $username, '', null, false); 43 $prefs->retrieve(); 44 $email = $prefs->getValue('alternate_email'); 45 /* Does the alternate email stored in prefs match the one submitted? */ 46 if ($vars->get('email') == $email) { 47 $can_validate = true; 48 $form->setButtons(_("Reset Password")); 49 $question = $prefs->getValue('security_question'); 50 $form->addVariable($question, 'question', 'description', false); 51 $form->addVariable(_("Answer"), 'answer', 'text', true); 52 } else { 53 $notification->push(_("Incorrect username or alternate address. Try again or contact your administrator if you need further help."), 'horde.error'); 54 } 55 } 56 57 /* Validate the form. */ 58 if ($can_validate && $form->validate($vars)) { 59 $form->getInfo($vars, $info); 60 61 /* Fetch values from prefs for selected user. */ 62 $answer = $prefs->getValue('security_answer'); 63 64 /* Check the given values witht the prefs stored ones. */ 65 if ($email == $info['email'] && String::lower($answer) == String::lower($info['answer'])) { 66 /* Info matches, so reset the password. */ 67 $password = $auth->resetPassword($info['username']); 68 69 require_once 'Mail.php'; 70 $mailer = Mail::factory($conf['mailer']['type'], $conf['mailer']['params']); 71 72 /* Set up the email headers and body. */ 73 $headers['From'] = $email; 74 $headers['To'] = $email; 75 $recipients[] = $headers['To']; 76 $headers['Subject'] = _("Your password has been reset"); 77 $body = sprintf(_("Your new password for %s is: %s"), $registry->get('name', 'horde'), $password); 78 $mailer->send($recipients, $headers, $body); 79 80 $notification->push(_("Your password has been reset, check your email and log in with your new password."), 'horde.success'); 81 header('Location: ' . Auth::getLoginScreen('', $info['url'])); 82 exit; 83 } else { 84 /* Info submitted does not match what is in prefs, redirect user back 85 * to login. */ 86 $notification->push(_("Could not reset the password for the requested user. Some or all of the details are not correct. Try again or contact your administrator if you need further help."), 'horde.error'); 87 } 88 } 89 90 require HORDE_TEMPLATES . '/common-header.inc'; 91 $notification->notify(array('listeners' => 'status')); 92 require_once 'Horde/Form/Renderer.php'; 93 $renderer = &new Horde_Form_Renderer(); 94 $form->renderActive($renderer, $vars, 'resetpassword.php', 'post'); 95 require HORDE_TEMPLATES . '/common-footer.inc';
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |