1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
17
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2005, Ryan Djurovich
|
9 |
|
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
if(!defined('WB_URL')) {
|
27 |
17
|
stefan
|
header('Location: ../pages/index.php');
|
28 |
4
|
ryan
|
}
|
29 |
|
|
|
30 |
|
|
// Create new database object
|
31 |
|
|
$database = new database();
|
32 |
|
|
|
33 |
|
|
// Get details entered
|
34 |
|
|
$group_id = FRONTEND_SIGNUP;
|
35 |
|
|
$active = 1;
|
36 |
|
|
$username = strtolower($admin->get_post('username'));
|
37 |
|
|
$display_name = $admin->get_post('display_name');
|
38 |
|
|
$email = $admin->get_post('email');
|
39 |
|
|
|
40 |
|
|
// Create a javascript back link
|
41 |
|
|
$js_back = "javascript: history.go(-1);";
|
42 |
|
|
|
43 |
|
|
// Check values
|
44 |
|
|
if($group_id == "") {
|
45 |
|
|
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
|
46 |
|
|
}
|
47 |
|
|
if(strlen($username) < 3) {
|
48 |
|
|
$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
|
49 |
|
|
}
|
50 |
|
|
if($email != "") {
|
51 |
|
|
if($admin->validate_email($email) == false) {
|
52 |
|
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
53 |
|
|
}
|
54 |
|
|
} else {
|
55 |
|
|
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// Generate a random password then update the database with it
|
59 |
|
|
$new_pass = '';
|
60 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
61 |
|
|
srand((double)microtime()*1000000);
|
62 |
|
|
$i = 0;
|
63 |
|
|
while ($i <= 7) {
|
64 |
|
|
$num = rand() % 33;
|
65 |
|
|
$tmp = substr($salt, $num, 1);
|
66 |
|
|
$new_pass = $new_pass . $tmp;
|
67 |
|
|
$i++;
|
68 |
|
|
}
|
69 |
|
|
$md5_password = md5($new_pass);
|
70 |
|
|
|
71 |
|
|
// Check if username already exists
|
72 |
|
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
73 |
|
|
if($results->numRows() > 0) {
|
74 |
|
|
$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
// Check if the email already exists
|
78 |
106
|
stefan
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'");
|
79 |
4
|
ryan
|
if($results->numRows() > 0) {
|
80 |
|
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
|
81 |
|
|
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
|
82 |
|
|
} else {
|
83 |
|
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
// MD5 supplied password
|
88 |
|
|
$md5_password = md5($new_pass);
|
89 |
|
|
|
90 |
|
|
// Inser the user into the database
|
91 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,active,username,password,display_name,email) VALUES ('$group_id', '$active', '$username','$md5_password','$display_name','$email')";
|
92 |
|
|
$database->query($query);
|
93 |
|
|
|
94 |
|
|
if($database->is_error()) {
|
95 |
|
|
// Error updating database
|
96 |
|
|
$message = $database->get_error();
|
97 |
|
|
} else {
|
98 |
|
|
// Setup email to send
|
99 |
|
|
$mail_subject = 'Your login details...';
|
100 |
|
|
$mail_to = $email;
|
101 |
|
|
$mail_message = ''.
|
102 |
|
|
'Hello '.$display_name.',
|
103 |
|
|
|
104 |
|
|
Your '.WEBSITE_TITLE.' login details are:
|
105 |
|
|
Username: '.$username.'
|
106 |
|
|
Password: '.$new_pass.'
|
107 |
|
|
|
108 |
|
|
Your password has been set to the one above.
|
109 |
|
|
|
110 |
|
|
If you have recieved this message in error, please delete it immediatly.';
|
111 |
|
|
|
112 |
|
|
// Try sending the email
|
113 |
|
|
if(mail($mail_to, $mail_subject, $mail_message, 'From: '.SERVER_EMAIL)) {
|
114 |
|
|
$admin->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login'.PAGE_EXTENSION);
|
115 |
|
|
$display_form = false;
|
116 |
|
|
} else {
|
117 |
|
|
$admin->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back);
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
17
|
stefan
|
?>
|