source: trunk/password.php @ 1851

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

o Proposition: improved display of 'x images in y sub-categories' or 'x images in this category' for cases when categories contain both images and sub-categories
o Good idea of this new way for way confguest_access, but I kept last implementation for access methods (Could be useful on future development)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-02-22 20:20:30 +0000 (Thu, 22 Feb 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1851 $
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\', \'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'], $mailto);
136    }
137  }
138}
139
140// +-----------------------------------------------------------------------+
141// |                        template initialization                        |
142// +-----------------------------------------------------------------------+
143
144$title = l10n('Forgot your password?');
145$page['body_id'] = 'thePasswordPage';
146include(PHPWG_ROOT_PATH.'include/page_header.php');
147$template->set_filenames(array('password'=>'password.tpl'));
148
149$template->assign_vars(
150  array(
151    'U_HOME' => make_index_url(),
152    )
153  );
154
155// +-----------------------------------------------------------------------+
156// |                        infos & errors display                         |
157// +-----------------------------------------------------------------------+
158
159if (count($page['errors']) != 0)
160{
161  $template->assign_block_vars('errors', array());
162 
163  foreach ($page['errors'] as $error)
164  {
165    $template->assign_block_vars(
166      'errors.error',
167      array(
168        'ERROR' => $error
169        )
170      );
171  }
172}
173
174if (count($page['infos']) != 0)
175{
176  $template->assign_block_vars('infos', array());
177 
178  foreach ($page['infos'] as $info)
179  {
180    $template->assign_block_vars(
181      'infos.info',
182      array(
183        'INFO' => $info
184        )
185      );
186  }
187}
188
189// +-----------------------------------------------------------------------+
190// |                           html code display                           |
191// +-----------------------------------------------------------------------+
192
193$template->parse('password');
194include(PHPWG_ROOT_PATH.'include/page_tail.php');
195
196?>
Note: See TracBrowser for help on using the repository browser.