source: trunk/password.php @ 2223

Last change on this file since 2223 was 2223, checked in by rvelices, 16 years ago
  • migrate many templates to smarty
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: password.php 2223 2008-02-28 02:41:48Z rvelices $
8// | last update   : $Date: 2008-02-28 02:41:48 +0000 (Thu, 28 Feb 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2223 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27// +-----------------------------------------------------------------------+
28// |                           initialization                              |
29// +-----------------------------------------------------------------------+
30
31define('PHPWG_ROOT_PATH','./');
32include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
33include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_NONE);
39
40// +-----------------------------------------------------------------------+
41// |                          send a new password                          |
42// +-----------------------------------------------------------------------+
43
44$page['errors'] = array();
45$page['infos'] = array();
46
47if (isset($_POST['submit']))
48{
49  $mailto =
50    '<a href="mailto:'.get_webmaster_mail_address().'">'
51    .l10n('Contact webmaster')
52    .'</a>'
53    ;
54
55  if (isset($_POST['no_mail_address']) and $_POST['no_mail_address'] == 1)
56  {
57    array_push($page['infos'], l10n('Email address is missing'));
58    array_push($page['infos'], $mailto);
59  }
60  else if (isset($_POST['mail_address']) and !empty($_POST['mail_address']))
61  {
62    $mail_address = mysql_escape_string($_POST['mail_address']);
63   
64    $query = '
65SELECT '.$conf['user_fields']['id'].' AS id
66     , '.$conf['user_fields']['username'].' AS username
67     , '.$conf['user_fields']['email'].' AS email
68FROM '.USERS_TABLE.' as u
69  INNER JOIN '.USER_INFOS_TABLE.' AS ui
70      ON u.'.$conf['user_fields']['id'].' = ui.user_id
71WHERE '
72  .$conf['user_fields']['email'].' = \''.$mail_address.'\' AND
73  (
74    ui.status = \'normal\' OR
75    (ui.status in (\'admin\', \'webmaster\') AND ui.adviser = \'true\')
76  )
77;';
78    $result = pwg_query($query);
79
80    if (mysql_num_rows($result) > 0)
81    {
82      $error_on_mail = false;
83      $datas = array();
84     
85      while ($row = mysql_fetch_array($result))
86      {
87        $new_password = generate_key(6);
88
89        $infos =
90          l10n('Username').': '.$row['username']
91          ."\n".l10n('Password').': '.$new_password
92          ;
93
94        if (pwg_mail($row['email'],
95              array('subject' => l10n('password updated'), 'content' => $infos)))
96        {
97          $data =
98            array(
99              $conf['user_fields']['id']
100              => $row['id'],
101             
102              $conf['user_fields']['password']
103              => $conf['pass_convert']($new_password)
104              );
105
106          array_push($datas, $data);
107        }
108        else
109        {
110          $error_on_mail = true;
111        }
112      }
113     
114      if ($error_on_mail)
115      {
116        array_push($page['errors'], l10n('Error sending email'));
117        array_push($page['errors'], $mailto);
118      }
119      else
120      {
121        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
122        mass_updates(
123          USERS_TABLE,
124          array(
125            'primary' => array($conf['user_fields']['id']),
126            'update' => array($conf['user_fields']['password'])
127          ),
128          $datas
129          );
130
131        array_push($page['infos'], l10n('New password sent by email'));
132      }
133    }
134    else
135    {
136      array_push($page['errors'], l10n('No user matches this email address'));
137      array_push($page['errors'], l10n('Administrator, webmaster and special user cannot use this method'));
138      array_push($page['errors'], $mailto);
139    }
140  }
141}
142
143// +-----------------------------------------------------------------------+
144// |                        template initialization                        |
145// +-----------------------------------------------------------------------+
146
147$title = l10n('Forgot your password?');
148$page['body_id'] = 'thePasswordPage';
149
150$template->set_filenames(array('password'=>'password.tpl'));
151$template->assign( array(
152    'F_ACTION'=> get_root_url().'password.php'
153    )
154  );
155// +-----------------------------------------------------------------------+
156// |                        infos & errors display                         |
157// +-----------------------------------------------------------------------+
158$template->assign('errors', $page['errors']);
159$template->assign('infos', $page['infos']);
160
161// +-----------------------------------------------------------------------+
162// |                           html code display                           |
163// +-----------------------------------------------------------------------+
164include(PHPWG_ROOT_PATH.'include/page_header.php');
165$template->pparse('password');
166include(PHPWG_ROOT_PATH.'include/page_tail.php');
167
168?>
Note: See TracBrowser for help on using the repository browser.