1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
<?php /************************* Coppermine Photo Gallery ************************ Copyright (c) 2003-2008 Dev Team v1.1 originally written by Gregory DEMAR
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. ******************************************** Coppermine version: 1.4.19 $HeadURL: https://coppermine.svn.sourceforge.net/svnroot/coppermine/trunk/cpg1.4.x/register.php $ $Revision: 4392 $ $Author: gaugau $ $Date: 2008-04-16 09:25:35 +0200 (Mi, 16 Apr 2008) $ **********************************************/
define('IN_COPPERMINE', true); define('REGISTER_PHP', true);
require('include/init.inc.php'); require('include/mailer.inc.php');
if (!$CONFIG['allow_user_registration']) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
if (defined('UDB_INTEGRATION')) $cpg_udb->register_page(); // Display the disclaimer function display_disclaimer() { global $CONFIG; //, $PHP_SELF; global $lang_register_disclamer, $lang_register_php;
starttable(-1, $lang_register_php['term_cond']); echo <<<EOT <form method="post" action="{$_SERVER['PHP_SELF']}"> <tr> <td class="tableb" style="padding: 10px;">
EOT; echo str_replace('{SITE_NAME}', $CONFIG['gallery_name'], $lang_register_disclamer);
echo <<<EOT </td> </tr> <tr> <td colspan="2" align="center" class="tablef"> <input type="submit" name="agree" value="{$lang_register_php['i_agree']}" class="button" /> </td> </tr> </form>
EOT; endtable(); }
function input_user_info($errors = '') { global $CONFIG; //, $PHP_SELF; global $lang_register_php;
starttable(-1, $lang_register_php['enter_info'], 2); echo <<<EOT <form method="post" action="{$_SERVER['PHP_SELF']}">
EOT;
$form_data = array( array('label', $lang_register_php['required_info']), array('input', 'username', $lang_register_php['username'], 25), array('password', 'password', $lang_register_php['password'], 25), array('password', 'password_verification', $lang_register_php['password_again'], 25), array('input', 'email', $lang_register_php['email'], 255), array('label', $lang_register_php['optional_info']), array('input', 'user_profile1', $CONFIG['user_profile1_name'], 255), array('input', 'user_profile2', $CONFIG['user_profile2_name'], 255), array('input', 'user_profile3', $CONFIG['user_profile3_name'], 255), array('input', 'user_profile4', $CONFIG['user_profile4_name'], 255), array('input', 'user_profile5', $CONFIG['user_profile5_name'], 255), array('textarea', 'user_profile6', $CONFIG['user_profile6_name'], 255) );
foreach ($form_data as $element) switch ($element[0]) { case 'label' : echo <<<EOT <tr> <td colspan="2" class="tableh2"> <b>{$element[1]}<b> </td> </tr>
EOT; break;
case 'input' : if (isset($_POST[$element[1]])) { $value = $_POST[$element[1]]; } else { $value = ''; } if ($element[2]) echo <<<EOT <tr> <td width="40%" class="tableb" height="25"> {$element[2]} </td> <td width="60%" class="tableb" valign="top"> <input type="text" style="width: 100%" name="{$element[1]}" maxlength="{$element[3]}" value="$value" class="textinput" /> </td> </tr>
EOT; break;
case 'radio' : // added the radio option for possible future use. The array definition would have to look like this: // array('radio', 'user_var', 'Text label', 'option 1','option 2'), // enabling this option requires changes in profile.php and usermgr.php as well if (isset($_POST[$element[1]])) { $value = $_POST[$element[1]]; } else { $value = ''; } if ($element[2]) echo <<<EOT <tr> <td width="40%" class="tableb" height="25"> {$element[2]} </td> <td width="60%" class="tableb" valign="top"> <input type="radio" name="{$element[1]}" id="{$element[1]}1" value="{$element[3]}" class="radio" /><label for="{$element[1]}1" class="clickable_option">{$element[3]}</label> <input type="radio" name="{$element[1]}" id="{$element[1]}2" value="{$element[4]}" class="radio" /><label for="{$element[1]}2" class="clickable_option">{$element[4]}</label> </td> </tr>
EOT; break;
case 'textarea' : if (isset($_POST[$element[1]])) { $value = $_POST[$element[1]]; } else { $value = ''; } if ($element[2]) echo <<<EOT <tr> <td width="40%" class="tableb" height="25"> {$element[2]} </td> <td width="60%" class="tableb" valign="top"> <textarea name="{$element[1]}" rows="7" wrap="virtual" class="textinput" style="width:100%">$value</textarea> </td> </tr>
EOT; break;
case 'password' : echo <<<EOT <tr> <td width="40%" class="tableb" height="25"> {$element[2]} </td> <td width="60%" class="tableb" valign="top"> <input type="password" style="width: 100%" name="{$element[1]}" maxlength="{$element[3]}" value="" class="textinput" /> </td> </tr>
EOT; break;
default: cpg_die(CRITICAL_ERROR, 'Invalid action for form creation ' . $element[0], __FILE__, __LINE__); }
if ($errors) { echo <<<EOT <tr> <td colspan="2" class="tableh2" align="center"> <b>• • • {$lang_register_php['error']} • • •</b> </td> </tr> <tr> <td colspan="2" class="tableb"> <b><ul>$errors</ul><b> </td> </tr>
EOT; } echo <<<EOT <tr> <td colspan="2" align="center" class="tablef"> <input type="submit" name="submit" value="{$lang_register_php['submit']}" class="button" /> </td> </tr> </form>
EOT; endtable(); }
function get_post_var($var) { global $lang_errors;
if (!isset($_POST[$var])) cpg_die(CRITICAL_ERROR, $lang_errors['param_missing'] . " ($var)", __FILE__, __LINE__); return trim($_POST[$var]); }
function check_user_info(&$error) { global $CONFIG; //, $PHP_SELF; global $lang_register_php, $lang_register_confirm_email, $lang_continue, $lang_register_approve_email, $lang_register_activated_email, $lang_register_user_login; //$CONFIG['admin_activation'] = FALSE; //$CONFIG['admin_activation'] = TRUE;
$user_name = trim(get_post_var('username')); $password = trim(get_post_var('password')); $password_again = trim(get_post_var('password_verification')); $email = trim(get_post_var('email')); $profile1 = addslashes($_POST['user_profile1']); $profile2 = addslashes($_POST['user_profile2']); $profile3 = addslashes($_POST['user_profile3']); $profile4 = addslashes($_POST['user_profile4']); $profile5 = addslashes($_POST['user_profile5']); $profile6 = addslashes($_POST['user_profile6']);
$sql = "SELECT user_id " . "FROM {$CONFIG['TABLE_USERS']} " . "WHERE user_name = '" . addslashes($user_name) . "'"; $result = cpg_db_query($sql);
if (mysql_num_rows($result)) { $error = '<li>' . $lang_register_php['err_user_exists']; return false; } mysql_free_result($result);
if (utf_strlen($user_name) < 2) $error .= '<li>' . $lang_register_php['err_uname_short']; if (utf_strlen($password) < 2) $error .= '<li>' . $lang_register_php['err_password_short']; if ($password == $user_name) $error .= '<li>' . $lang_register_php['err_uname_pass_diff']; if ($password != $password_again) $error .= '<li>' . $lang_register_php['err_password_mismatch'];
if (!eregi("^[_\.0-9a-z\-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$", $email)) $error .= '<li>' . $lang_register_php['err_invalid_email'];
if ($error != '') return false;
if (!$CONFIG['allow_duplicate_emails_addr']) { $sql = "SELECT user_id " . "FROM {$CONFIG['TABLE_USERS']} " . "WHERE user_email = '" . addslashes($email) . "'"; $result = cpg_db_query($sql);
if (mysql_num_rows($result)) { $error = '<li>' . $lang_register_php['err_duplicate_email']; return false; }
mysql_free_result($result); }
if ($CONFIG['reg_requires_valid_email'] || $CONFIG['admin_activation']) { $active = 'NO'; list($usec, $sec) = explode(' ', microtime()); $seed = (float) $sec + ((float) $usec * 100000); srand($seed); $act_key = md5(uniqid(rand(), 1)); } else { $active = 'YES'; $act_key = ''; }
if ($CONFIG['enable_encrypted_passwords']) { $encpassword = md5($password); } else { $encpassword = $password; }
$sql = "INSERT INTO {$CONFIG['TABLE_USERS']} ". "(user_regdate, user_active, user_actkey, user_name, user_password, user_email, user_profile1, user_profile2, user_profile3, user_profile4, user_profile5, user_profile6) ". "VALUES (NOW(), '$active', '$act_key', '" . addslashes($user_name) . "', '" . addslashes($encpassword) . "', '" . addslashes($email) . "', '$profile1', '$profile2', '$profile3', '$profile4', '$profile5', '$profile6')"; if ($CONFIG['log_mode']) { log_write('New user "'.addslashes($user_name).'" created on '.date("F j, Y, g:i a"),CPG_ACCESS_LOG); } $result = cpg_db_query($sql);
if ($CONFIG['reg_requires_valid_email']) { if (!$CONFIG['admin_activation']==1) { //user gets activation email $act_link = rtrim($CONFIG['site_url'], '/') . '/register.php?activate=' . $act_key; $template_vars = array( '{SITE_NAME}' => $CONFIG['gallery_name'], '{USER_NAME}' => $user_name, '{ACT_LINK}' => $act_link ); if (!cpg_mail($email, sprintf($lang_register_php['confirm_email_subject'], $CONFIG['gallery_name']), nl2br(strtr($lang_register_confirm_email, $template_vars)))) { cpg_die(CRITICAL_ERROR, $lang_register_php['failed_sending_email'], __FILE__, __LINE__); } } if ($CONFIG['admin_activation']==1) { msg_box($lang_register_php['information'], $lang_register_php['thank_you_admin_activation'], $lang_continue, 'index.php'); } else { msg_box($lang_register_php['information'], $lang_register_php['thank_you'], $lang_continue, 'index.php'); } } else { msg_box($lang_register_php['information'], $lang_register_php['acct_active'], $lang_continue, 'index.php'); }
// email notification to admin if ($CONFIG['reg_notify_admin_email']) {
// get default language in which to inform the admin $lang_register_php_def = cpg_get_default_lang_var('lang_register_php'); $lang_register_approve_email_def = cpg_get_default_lang_var('lang_register_approve_email');
if ($CONFIG['admin_activation']==1) { $act_link = rtrim($CONFIG['site_url'], '/') . '/register.php?activate=' . $act_key; $template_vars = array( '{SITE_NAME}' => $CONFIG['gallery_name'], '{USER_NAME}' => $user_name, '{ACT_LINK}' => $act_link, ); cpg_mail('admin', sprintf($lang_register_php_def['notify_admin_request_email_subject'], $CONFIG['gallery_name']), nl2br(strtr($lang_register_approve_email_def, $template_vars))); } else { cpg_mail('admin', sprintf($lang_register_php_def['notify_admin_email_subject'], $CONFIG['gallery_name']), sprintf($lang_register_php_def['notify_admin_email_body'], $user_name)); } }
return true; }
if (isset($_GET['activate'])) { //$CONFIG['admin_activation'] = FALSE; //$CONFIG['admin_activation'] = TRUE;
$act_key = addslashes(substr($_GET['activate'], 0 , 32)); if (strlen($act_key) != 32) cpg_die(ERROR, $lang_register_php['acct_act_failed'], __FILE__, __LINE__);
$sql = "SELECT user_active user_active, user_email, user_name, user_password " . "FROM {$CONFIG['TABLE_USERS']} " . "WHERE user_actkey = '$act_key' " . "LIMIT 1"; $result = cpg_db_query($sql); if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['acct_act_failed'], __FILE__, __LINE__);
$row = mysql_fetch_array($result); mysql_free_result($result);
if ($row['user_active'] == 'YES') cpg_die(ERROR, $lang_register_php['acct_already_act'], __FILE__, __LINE__);
pageheader($lang_register_php['page_title']); $email = $row['user_email']; $user_name = $row['user_name']; $password = $row['user_password'];
$sql = "UPDATE {$CONFIG['TABLE_USERS']} " . "SET user_active = 'YES' " . "WHERE user_actkey = '$act_key' " . "LIMIT 1"; $result = cpg_db_query($sql);
if ($CONFIG['admin_activation']==1) { //after admin approves, user receives email notification msg_box($lang_register_php['information'], $lang_register_php['acct_active_admin_activation'], $lang_continue, 'index.php'); $site_link = $CONFIG['site_url']; $template_vars = array( '{SITE_LINK}' => $site_link, '{USER_NAME}' => $user_name, '{PASSWORD}' => $password, '{SITE_NAME}' => $CONFIG['gallery_name'], ); cpg_mail($email, sprintf($lang_register_php['notify_user_email_subject'], $CONFIG['gallery_name']), nl2br(strtr($lang_register_activated_email, $template_vars))); } else { //user self-activated, gets message box that account was activated msg_box($lang_register_php['information'], $lang_register_php['acct_active'], $lang_continue, 'index.php'); } } else { pageheader($lang_register_php['page_title']); if (isset($_POST['agree'])) { input_user_info(); } elseif (isset($_POST['submit'])) { $errors = ''; if (!check_user_info($errors)) { input_user_info($errors); } } else { display_disclaimer(); } } pagefooter(); ob_end_flush();
?>
|