- Allow blacklisting and whitelisting of e-mail addresses used for new user accounts
[scuttle] / password.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2005 Scuttle project
4 http://sourceforge.net/projects/scuttle/
5 http://scuttle.org/
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 ***************************************************************************/
21
22 require_once('header.inc.php');
23 $userservice =& ServiceFactory::getServiceInstance('UserService');
24 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
25 $tplVars = array();
26
27 // IF SUBMITTED
28 if ($_POST['submitted']) {
29
30     // NO USERNAME
31     if (!$_POST['username']) {
32         $tplVars['error'] = T_('You must enter your username.');
33
34     // NO E-MAIL
35     } elseif (!$_POST['email']) {
36         $tplVars['error'] = T_('You must enter your <abbr title="electronic mail">e-mail</abbr> address.');
37
38     // USERNAME AND E-MAIL
39     } else {
40
41         // NO MATCH
42         if (!($userinfo = $userservice->getUserByUsername($_POST['username']))) {
43             $tplVars['error'] = T_('No matches found for that username.');
44
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.');
47
48         // MATCH
49         } else {
50
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.');    
55
56             } else {
57                 // SEND E-MAIL
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);
62
63                 $tplVars['msg'] = sprintf(T_('New password generated and sent to %s'), $_POST['email']);
64             }
65         }
66     }
67 }
68
69 $templatename = 'password.tpl';
70 $tplVars['subtitle'] = T_('Forgotten Password');
71 $tplVars['formaction']  = createURL('password');
72 $templateservice->loadTemplate($templatename, $tplVars);
73 ?>

Benjamin Mako Hill || Want to submit a patch?