source: trunk/password.php @ 1947

Last change on this file since 1947 was 1947, checked in by rub, 17 years ago

Issue 674:

Administrator can ask a new password
Add message about users witch can change their password

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-04-07 22:31:37 +0000 (Sat, 07 Apr 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1947 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28// +-----------------------------------------------------------------------+
29// |                           initialization                              |
30// +-----------------------------------------------------------------------+
31
32define('PHPWG_ROOT_PATH','./');
33include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
34include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
35
36// +-----------------------------------------------------------------------+
37// | Check Access and exit when user status is not ok                      |
38// +-----------------------------------------------------------------------+
39check_status(ACCESS_NONE);
40
41// +-----------------------------------------------------------------------+
42// |                          send a new password                          |
43// +-----------------------------------------------------------------------+
44
45$page['errors'] = array();
46$page['infos'] = array();
47
48if (isset($_POST['submit']))
49{
50  $mailto =
51    '<a href="mailto:'.get_webmaster_mail_address().'">'
52    .l10n('Contact webmaster')
53    .'</a>'
54    ;
55
56  if (isset($_POST['no_mail_address']) and $_POST['no_mail_address'] == 1)
57  {
58    array_push($page['infos'], l10n('Email address is missing'));
59    array_push($page['infos'], $mailto);
60  }
61  else if (isset($_POST['mail_address']) and !empty($_POST['mail_address']))
62  {
63    $mail_address = mysql_escape_string($_POST['mail_address']);
64   
65    $query = '
66SELECT '.$conf['user_fields']['id'].' AS id
67     , '.$conf['user_fields']['username'].' AS username
68     , '.$conf['user_fields']['email'].' AS email
69FROM '.USERS_TABLE.' as u
70  INNER JOIN '.USER_INFOS_TABLE.' AS ui
71      ON u.'.$conf['user_fields']['id'].' = ui.user_id
72WHERE '
73  .$conf['user_fields']['email'].' = \''.$mail_address.'\' AND
74  ui.status not in (\'guest\', \'generic\', \'admin\', \'webmaster\')
75;';
76    $result = pwg_query($query);
77
78    if (mysql_num_rows($result) > 0)
79    {
80      $error_on_mail = false;
81      $datas = array();
82     
83      while ($row = mysql_fetch_array($result))
84      {
85        $new_password = generate_key(6);
86
87        $infos =
88          l10n('Username').': '.$row['username']
89          ."\n".l10n('Password').': '.$new_password
90          ;
91
92        if (pwg_mail($row['email'],
93              array('subject' => l10n('password updated'), 'content' => $infos)))
94        {
95          $data =
96            array(
97              $conf['user_fields']['id']
98              => $row['id'],
99             
100              $conf['user_fields']['password']
101              => $conf['pass_convert']($new_password)
102              );
103
104          array_push($datas, $data);
105        }
106        else
107        {
108          $error_on_mail = true;
109        }
110      }
111     
112      if ($error_on_mail)
113      {
114        array_push($page['errors'], l10n('Error sending email'));
115        array_push($page['errors'], $mailto);
116      }
117      else
118      {
119        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
120        mass_updates(
121          USERS_TABLE,
122          array(
123            'primary' => array($conf['user_fields']['id']),
124            'update' => array($conf['user_fields']['password'])
125          ),
126          $datas
127          );
128
129        array_push($page['infos'], l10n('New password sent by email'));
130      }
131    }
132    else
133    {
134      array_push($page['errors'], l10n('No user matches this email address'));
135      array_push($page['errors'], l10n('Administrator, webmaster and special user cannot use this method'));
136      array_push($page['errors'], $mailto);
137    }
138  }
139}
140
141// +-----------------------------------------------------------------------+
142// |                        template initialization                        |
143// +-----------------------------------------------------------------------+
144
145$title = l10n('Forgot your password?');
146$page['body_id'] = 'thePasswordPage';
147include(PHPWG_ROOT_PATH.'include/page_header.php');
148$template->set_filenames(array('password'=>'password.tpl'));
149
150$template->assign_vars(
151  array(
152    'U_HOME' => make_index_url(),
153    )
154  );
155
156// +-----------------------------------------------------------------------+
157// |                        infos & errors display                         |
158// +-----------------------------------------------------------------------+
159
160if (count($page['errors']) != 0)
161{
162  $template->assign_block_vars('errors', array());
163 
164  foreach ($page['errors'] as $error)
165  {
166    $template->assign_block_vars(
167      'errors.error',
168      array(
169        'ERROR' => $error
170        )
171      );
172  }
173}
174
175if (count($page['infos']) != 0)
176{
177  $template->assign_block_vars('infos', array());
178 
179  foreach ($page['infos'] as $info)
180  {
181    $template->assign_block_vars(
182      'infos.info',
183      array(
184        'INFO' => $info
185        )
186      );
187  }
188}
189
190// +-----------------------------------------------------------------------+
191// |                           html code display                           |
192// +-----------------------------------------------------------------------+
193
194$template->parse('password');
195include(PHPWG_ROOT_PATH.'include/page_tail.php');
196
197?>
Note: See TracBrowser for help on using the repository browser.