- Override privacy status on bookmark file import, if specified (i.e. Delicious)
[scuttle] / password.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2005 Marcus Campbell
4 http://scuttle.org/
5
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.
10
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.
15
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 ***************************************************************************/
20
21 require_once 'header.inc.php';
22 $userservice =& ServiceFactory::getServiceInstance('UserService');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
24 $tplVars = array();
25
26 // IF SUBMITTED
27 if ($_POST['submitted']) {
28
29     // NO USERNAME
30     if (!$_POST['username']) {
31         $tplVars['error'] = T_('You must enter your username.');
32
33     // NO E-MAIL
34     } elseif (!$_POST['email']) {
35         $tplVars['error'] = T_('You must enter your <abbr title="electronic mail">e-mail</abbr> address.');
36
37     // USERNAME AND E-MAIL
38     } else {
39
40         // NO MATCH
41         if (!($userinfo = $userservice->getUserByUsername($_POST['username']))) {
42             $tplVars['error'] = T_('No matches found for that username.');
43
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.');
46
47         // MATCH
48         } else {
49
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.');    
54
55             } else {
56                 // SEND E-MAIL
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);
61
62                 $tplVars['msg'] = sprintf(T_('New password generated and sent to %s'), $_POST['email']);
63             }
64         }
65     }
66 }
67
68 $templatename = 'password.tpl';
69 $tplVars['subtitle'] = T_('Forgotten Password');
70 $tplVars['formaction']  = createURL('password');
71 $templateservice->loadTemplate($templatename, $tplVars);
72 ?>

Benjamin Mako Hill || Want to submit a patch?