1 |
1473
|
Luisehahne
|
<?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$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
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 |
1508
|
Luisehahne
|
// require_once(WB_PATH.'/framework/class.wb.php');
|
23 |
1473
|
Luisehahne
|
$wb = new wb('Start', 'start', false, false);
|
24 |
|
|
|
25 |
1508
|
Luisehahne
|
$_SESSION['PAGE_LINK'] = get_page_link( $_SESSION['PAGE_ID'] );
|
26 |
|
|
$_SESSION['HTTP_REFERER'] = page_link($_SESSION['PAGE_LINK']);
|
27 |
|
|
|
28 |
1473
|
Luisehahne
|
// Create new database object
|
29 |
|
|
// $database = new database();
|
30 |
|
|
|
31 |
|
|
// Get details entered
|
32 |
|
|
$groups_id = FRONTEND_SIGNUP;
|
33 |
|
|
$active = 1;
|
34 |
|
|
$username = strtolower(strip_tags($wb->get_post_escaped('username')));
|
35 |
|
|
$display_name = strip_tags($wb->get_post_escaped('display_name'));
|
36 |
|
|
$email = $wb->get_post('email');
|
37 |
|
|
|
38 |
|
|
// Create a javascript back link
|
39 |
|
|
$js_back = WB_URL.'/account/signup.php';
|
40 |
|
|
/*
|
41 |
|
|
if (!$wb->checkFTAN())
|
42 |
|
|
{
|
43 |
|
|
$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back, false);
|
44 |
|
|
exit();
|
45 |
|
|
}
|
46 |
|
|
*/
|
47 |
|
|
// Check values
|
48 |
|
|
if($groups_id == "") {
|
49 |
|
|
$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
|
50 |
|
|
}
|
51 |
|
|
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
|
52 |
|
|
$wb->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
|
53 |
|
|
$MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
|
54 |
|
|
}
|
55 |
|
|
if($email != "") {
|
56 |
|
|
if($wb->validate_email($email) == false) {
|
57 |
|
|
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
|
58 |
|
|
}
|
59 |
|
|
} else {
|
60 |
|
|
$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
$email = $wb->add_slashes($email);
|
64 |
|
|
|
65 |
|
|
// Captcha
|
66 |
|
|
if(ENABLED_CAPTCHA) {
|
67 |
|
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
68 |
|
|
// Check for a mismatch
|
69 |
|
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
70 |
|
|
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
|
71 |
|
|
}
|
72 |
|
|
} else {
|
73 |
|
|
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
77 |
|
|
|
78 |
|
|
// Generate a random password then update the database with it
|
79 |
|
|
$new_pass = '';
|
80 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
81 |
|
|
srand((double)microtime()*1000000);
|
82 |
|
|
$i = 0;
|
83 |
|
|
while ($i <= 7) {
|
84 |
|
|
$num = rand() % 33;
|
85 |
|
|
$tmp = substr($salt, $num, 1);
|
86 |
|
|
$new_pass = $new_pass . $tmp;
|
87 |
|
|
$i++;
|
88 |
|
|
}
|
89 |
|
|
$md5_password = md5($new_pass);
|
90 |
|
|
|
91 |
|
|
// Check if username already exists
|
92 |
|
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
93 |
|
|
if($results->numRows() > 0) {
|
94 |
|
|
$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
// Check if the email already exists
|
98 |
|
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'");
|
99 |
|
|
if($results->numRows() > 0) {
|
100 |
|
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
|
101 |
|
|
$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
|
102 |
|
|
} else {
|
103 |
|
|
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
// MD5 supplied password
|
108 |
|
|
$md5_password = md5($new_pass);
|
109 |
|
|
|
110 |
|
|
// Inser the user into the database
|
111 |
|
|
$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')";
|
112 |
|
|
$database->query($query);
|
113 |
|
|
|
114 |
|
|
if($database->is_error()) {
|
115 |
|
|
// Error updating database
|
116 |
|
|
$message = $database->get_error();
|
117 |
|
|
} else {
|
118 |
|
|
// Setup email to send
|
119 |
|
|
$mail_to = $email;
|
120 |
|
|
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
|
121 |
|
|
|
122 |
|
|
// Replace placeholders from language variable with values
|
123 |
|
|
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
|
124 |
|
|
$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass);
|
125 |
|
|
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
|
126 |
|
|
|
127 |
|
|
// Try sending the email
|
128 |
|
|
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
|
129 |
|
|
$display_form = false;
|
130 |
|
|
$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php' );
|
131 |
|
|
} else {
|
132 |
|
|
$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
133 |
|
|
$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
|
134 |
|
|
}
|
135 |
|
|
}
|