2 /***************************************************************************
3 Copyright (c) 2005 Marcus Campbell
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************/
21 require_once 'header.inc.php';
22 $sf = new ServiceFactory();
23 $userservice =& $sf->getServiceInstance('UserService');
24 $templateservice =& $sf->getServiceInstance('TemplateService');
28 if ($_POST['submitted']) {
31 if (!$_POST['username']) {
32 $tplVars['error'] = T_('You must enter your username.');
35 } elseif (!$_POST['email']) {
36 $tplVars['error'] = T_('You must enter your <abbr title="electronic mail">e-mail</abbr> address.');
38 // USERNAME AND E-MAIL
42 if (!($userinfo = $userservice->getUserByUsername($_POST['username']))) {
43 $tplVars['error'] = T_('No matches found for that username.');
45 } elseif ($_POST['email'] != $userinfo['email']) {
46 $tplVars['error'] = T_('No matches found for that combination of username and <abbr title="electronic mail">e-mail</abbr> address.');
51 // GENERATE AND STORE PASSWORD
52 $password = $userservice->generatePassword($userinfo['uId']);
53 if (!($password = $userservice->generatePassword($userinfo['uId']))) {
54 $tplVars['error'] = T_('There was an error while generating your new password. Please try again.');
58 $message = T_('Your new password is:') ."\n". $password ."\n\n". T_('To keep your bookmarks secure, you should change this password in your profile the next time you log in.');
59 $message = wordwrap($message, 70);
60 $headers = 'From: '. $adminemail;
61 $mail = mail($_POST['email'], sprintf(T_('%s Account Information'), $sitename), $message);
63 $tplVars['msg'] = sprintf(T_('New password generated and sent to %s'), $_POST['email']);
69 $templatename = 'password.tpl';
70 $tplVars['subtitle'] = T_('Forgotten Password');
71 $tplVars['formaction'] = createURL('password');
72 $templateservice->loadTemplate($templatename, $tplVars);