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 | // | file : $Id: password.php 1951 2007-04-10 05:26:48Z rub $ |
---|
8 | // | last update : $Date: 2007-04-10 05:26:48 +0000 (Tue, 10 Apr 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 1951 $ |
---|
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 | |
---|
31 | define('PHPWG_ROOT_PATH','./'); |
---|
32 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
33 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_NONE); |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | send a new password | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | $page['errors'] = array(); |
---|
45 | $page['infos'] = array(); |
---|
46 | |
---|
47 | if (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 = ' |
---|
65 | SELECT '.$conf['user_fields']['id'].' AS id |
---|
66 | , '.$conf['user_fields']['username'].' AS username |
---|
67 | , '.$conf['user_fields']['email'].' AS email |
---|
68 | FROM '.USERS_TABLE.' as u |
---|
69 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
70 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
71 | WHERE ' |
---|
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 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
150 | $template->set_filenames(array('password'=>'password.tpl')); |
---|
151 | |
---|
152 | $template->assign_vars( |
---|
153 | array( |
---|
154 | 'U_HOME' => make_index_url(), |
---|
155 | ) |
---|
156 | ); |
---|
157 | |
---|
158 | // +-----------------------------------------------------------------------+ |
---|
159 | // | infos & errors display | |
---|
160 | // +-----------------------------------------------------------------------+ |
---|
161 | |
---|
162 | if (count($page['errors']) != 0) |
---|
163 | { |
---|
164 | $template->assign_block_vars('errors', array()); |
---|
165 | |
---|
166 | foreach ($page['errors'] as $error) |
---|
167 | { |
---|
168 | $template->assign_block_vars( |
---|
169 | 'errors.error', |
---|
170 | array( |
---|
171 | 'ERROR' => $error |
---|
172 | ) |
---|
173 | ); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | if (count($page['infos']) != 0) |
---|
178 | { |
---|
179 | $template->assign_block_vars('infos', array()); |
---|
180 | |
---|
181 | foreach ($page['infos'] as $info) |
---|
182 | { |
---|
183 | $template->assign_block_vars( |
---|
184 | 'infos.info', |
---|
185 | array( |
---|
186 | 'INFO' => $info |
---|
187 | ) |
---|
188 | ); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | // +-----------------------------------------------------------------------+ |
---|
193 | // | html code display | |
---|
194 | // +-----------------------------------------------------------------------+ |
---|
195 | |
---|
196 | $template->parse('password'); |
---|
197 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
198 | |
---|
199 | ?> |
---|