1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category frontend
|
5
|
* @package account
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2004-2009, Ryan Djurovich
|
8
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9
|
* @link http://www.websitebaker2.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.x
|
12
|
* @requirements PHP 5.2.2 and higher
|
13
|
* @version $Id: signup2.php 1420 2011-01-26 17:43:56Z Luisehahne $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/signup2.php $
|
15
|
* @lastmodified $Date: 2011-01-26 18:43:56 +0100 (Wed, 26 Jan 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
// Must include code to stop this file being access directly
|
20
|
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
|
21
|
|
22
|
require_once(WB_PATH.'/framework/class.wb.php');
|
23
|
$wb = new wb('Start', 'start', false, false);
|
24
|
|
25
|
// Create new database object
|
26
|
// $database = new database();
|
27
|
|
28
|
// Get details entered
|
29
|
$groups_id = FRONTEND_SIGNUP;
|
30
|
$active = 1;
|
31
|
$username = strtolower(strip_tags($wb->get_post_escaped('username')));
|
32
|
$display_name = strip_tags($wb->get_post_escaped('display_name'));
|
33
|
$email = $wb->get_post('email');
|
34
|
|
35
|
if (!$wb->checkFTAN())
|
36
|
{
|
37
|
$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], WB_URL);
|
38
|
exit();
|
39
|
}
|
40
|
|
41
|
// Create a javascript back link
|
42
|
$js_back = "javascript: history.go(-1);";
|
43
|
|
44
|
// Check values
|
45
|
if($groups_id == "") {
|
46
|
$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
|
47
|
}
|
48
|
if(strlen($username) < 3) {
|
49
|
$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false);
|
50
|
}
|
51
|
if($email != "") {
|
52
|
if($wb->validate_email($email) == false) {
|
53
|
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
|
54
|
}
|
55
|
} else {
|
56
|
$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
|
57
|
}
|
58
|
|
59
|
$email = $wb->add_slashes($email);
|
60
|
|
61
|
// Captcha
|
62
|
if(ENABLED_CAPTCHA) {
|
63
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
64
|
// Check for a mismatch
|
65
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
66
|
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
|
67
|
}
|
68
|
} else {
|
69
|
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
|
70
|
}
|
71
|
}
|
72
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
73
|
|
74
|
// Generate a random password then update the database with it
|
75
|
$new_pass = '';
|
76
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
77
|
srand((double)microtime()*1000000);
|
78
|
$i = 0;
|
79
|
while ($i <= 7) {
|
80
|
$num = rand() % 33;
|
81
|
$tmp = substr($salt, $num, 1);
|
82
|
$new_pass = $new_pass . $tmp;
|
83
|
$i++;
|
84
|
}
|
85
|
$md5_password = md5($new_pass);
|
86
|
|
87
|
// Check if username already exists
|
88
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
89
|
if($results->numRows() > 0) {
|
90
|
$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
|
91
|
}
|
92
|
|
93
|
// Check if the email already exists
|
94
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'");
|
95
|
if($results->numRows() > 0) {
|
96
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
|
97
|
$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
|
98
|
} else {
|
99
|
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
// MD5 supplied password
|
104
|
$md5_password = md5($new_pass);
|
105
|
|
106
|
// Inser the user into the database
|
107
|
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,email) VALUES ('$groups_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$email')";
|
108
|
$database->query($query);
|
109
|
|
110
|
if($database->is_error()) {
|
111
|
// Error updating database
|
112
|
$message = $database->get_error();
|
113
|
} else {
|
114
|
// Setup email to send
|
115
|
$mail_to = $email;
|
116
|
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
|
117
|
|
118
|
// Replace placeholders from language variable with values
|
119
|
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
|
120
|
$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass);
|
121
|
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
|
122
|
|
123
|
// Try sending the email
|
124
|
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
|
125
|
$display_form = false;
|
126
|
$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php');
|
127
|
} else {
|
128
|
$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
129
|
$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
|
130
|
}
|
131
|
}
|
132
|
|
133
|
?>
|