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 $userservice =& ServiceFactory::getServiceInstance('UserService');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
27 if ($_POST['submitted']) {
30 if (!$_POST['username']) {
31 $tplVars['error'] = T_('You must enter your username.');
34 } elseif (!$_POST['email']) {
35 $tplVars['error'] = T_('You must enter your <abbr title="electronic mail">e-mail</abbr> address.');
37 // USERNAME AND E-MAIL
41 if (!($userinfo = $userservice->getUserByUsername($_POST['username']))) {
42 $tplVars['error'] = T_('No matches found for that username.');
44 } elseif ($_POST['email'] != $userinfo['email']) {
45 $tplVars['error'] = T_('No matches found for that combination of username and <abbr title="electronic mail">e-mail</abbr> address.');
50 // GENERATE AND STORE PASSWORD
51 $password = $userservice->generatePassword($userinfo['uId']);
52 if (!($password = $userservice->generatePassword($userinfo['uId']))) {
53 $tplVars['error'] = T_('There was an error while generating your new password. Please try again.');
57 $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.');
58 $message = wordwrap($message, 70);
59 $headers = 'From: '. $adminemail;
60 $mail = mail($_POST['email'], sprintf(T_('%s Account Information'), $sitename), $message);
62 $tplVars['msg'] = sprintf(T_('New password generated and sent to %s'), $_POST['email']);
68 $templatename = 'password.tpl';
69 $tplVars['subtitle'] = T_('Forgotten Password');
70 $tplVars['formaction'] = createURL('password');
71 $templateservice->loadTemplate($templatename, $tplVars);