source: trunk/password.php @ 1030

Last change on this file since 1030 was 1018, checked in by rub, 19 years ago

[NBM] Step 1: Create new include files with current notification/mail fonctions (with improvement)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 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: 2006-01-31 23:38:48 +0000 (Tue, 31 Jan 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1018 $
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// |                          send a new password                          |
38// +-----------------------------------------------------------------------+
39
40$page['errors'] = array();
41$page['infos'] = array();
42
43if (isset($_POST['submit']))
44{
45  // in case of error, creation of mailto link
46  $query = '
47SELECT '.$conf['user_fields']['email'].'
48  FROM '.USERS_TABLE.'
49  WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].'
50;';
51  list($mail_webmaster) = mysql_fetch_array(pwg_query($query));
52
53  $mailto =
54    '<a href="mailto:'.$mail_webmaster.'">'
55    .l10n('Contact webmaster')
56    .'</a>'
57    ;
58
59  if (isset($_POST['no_mail_address']) and $_POST['no_mail_address'] == 1)
60  {
61    array_push($page['infos'], l10n('Email address is missing'));
62    array_push($page['infos'], $mailto);
63  }
64  else if (isset($_POST['mail_address']) and !empty($_POST['mail_address']))
65  {
66    $mail_address = mysql_escape_string($_POST['mail_address']);
67   
68    $query = '
69SELECT '.$conf['user_fields']['id'].' AS id
70     , '.$conf['user_fields']['username'].' AS username
71     , '.$conf['user_fields']['email'].' AS email
72  FROM '.USERS_TABLE.'
73  WHERE '.$conf['user_fields']['email'].' = \''.$mail_address.'\'
74;';
75    $result = pwg_query($query);
76
77    if (mysql_num_rows($result) > 0)
78    {
79      $error_on_mail = false;
80      $datas = array();
81     
82      while ($row = mysql_fetch_array($result))
83      {
84        $new_password = generate_key(6);
85
86        $infos =
87          l10n('Username').': '.$row['username']
88          ."\n".l10n('Password').': '.$new_password
89          ;
90
91        if (pwg_mail($row['email'], $mail_webmaster, l10n('password updated'), $infos))
92        {
93          $data =
94            array(
95              $conf['user_fields']['id']
96              => $row['id'],
97             
98              $conf['user_fields']['password']
99              => $conf['pass_convert']($new_password)
100              );
101
102          array_push($datas, $data);
103        }
104        else
105        {
106          $error_on_mail = true;
107        }
108      }
109     
110      if ($error_on_mail)
111      {
112        array_push($page['errors'], l10n('Error sending email'));
113        array_push($page['errors'], $mailto);
114      }
115      else
116      {
117        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
118        mass_updates(
119          USERS_TABLE,
120          array(
121            'primary' => array($conf['user_fields']['id']),
122            'update' => array($conf['user_fields']['password'])
123          ),
124          $datas
125          );
126
127        array_push($page['infos'], l10n('New password sent by email'));
128      }
129    }
130    else
131    {
132      array_push($page['errors'], l10n('No user matches this email address'));
133      array_push($page['errors'], $mailto);
134    }
135  }
136}
137
138// +-----------------------------------------------------------------------+
139// |                        template initialization                        |
140// +-----------------------------------------------------------------------+
141
142$title = l10n('Forgot your password?');
143$page['body_id'] = 'thePasswordPage';
144include(PHPWG_ROOT_PATH.'include/page_header.php');
145$template->set_filenames(array('password'=>'password.tpl'));
146
147$template->assign_vars(
148  array(
149    'U_HOME' => PHPWG_ROOT_PATH.'category.php'
150    )
151  );
152
153// +-----------------------------------------------------------------------+
154// |                        infos & errors display                         |
155// +-----------------------------------------------------------------------+
156
157if (count($page['errors']) != 0)
158{
159  $template->assign_block_vars('errors', array());
160 
161  foreach ($page['errors'] as $error)
162  {
163    $template->assign_block_vars(
164      'errors.error',
165      array(
166        'ERROR' => $error
167        )
168      );
169  }
170}
171
172if (count($page['infos']) != 0)
173{
174  $template->assign_block_vars('infos', array());
175 
176  foreach ($page['infos'] as $info)
177  {
178    $template->assign_block_vars(
179      'infos.info',
180      array(
181        'INFO' => $info
182        )
183      );
184  }
185}
186
187// +-----------------------------------------------------------------------+
188// |                           html code display                           |
189// +-----------------------------------------------------------------------+
190
191$template->parse('password');
192include(PHPWG_ROOT_PATH.'include/page_tail.php');
193
194?>
Note: See TracBrowser for help on using the repository browser.