Project

General

Profile

1 1262 Luisehahne
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10
*                       LICENSE INFORMATION
11
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29
*/
30
/**
31
 *
32
 * @category        frontend
33
 * @package         account
34 1268 Luisehahne
 * @author          WebsiteBaker Project
35 1262 Luisehahne
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41 1268 Luisehahne
 * @version         $Id$
42
 * @filesource		$HeadURL$
43 1262 Luisehahne
 * @lastmodified    $Date$
44
 *
45
 */
46
47
if(!defined('WB_URL')) {
48
	header('Location: ../pages/index.php');
49
	exit(0);
50
}
51
52
require_once(WB_PATH.'/framework/class.wb.php');
53
$wb = new wb('Start', 'start', false, false);
54
55
// Create new database object
56
$database = new database();
57
58
// Get details entered
59
$groups_id = FRONTEND_SIGNUP;
60
$active = 1;
61
$username = strtolower(strip_tags($wb->get_post_escaped('username')));
62
$display_name = strip_tags($wb->get_post_escaped('display_name'));
63
$email = $wb->get_post('email');
64
65
// Create a javascript back link
66
$js_back = "javascript: history.go(-1);";
67
68
// Check values
69
if($groups_id == "") {
70
	$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
71
}
72
if(strlen($username) < 3) {
73
	$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false);
74
}
75
if($email != "") {
76
	if($wb->validate_email($email) == false) {
77
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
78
	}
79
} else {
80
	$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
81
}
82
83
$email = $wb->add_slashes($email);
84
85
// Captcha
86
if(ENABLED_CAPTCHA) {
87
	if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
88
		// Check for a mismatch
89
		if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
90
			$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
91
		}
92
	} else {
93
		$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
94
	}
95
}
96
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
97
98
// Generate a random password then update the database with it
99
$new_pass = '';
100
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
101
srand((double)microtime()*1000000);
102
$i = 0;
103
while ($i <= 7) {
104
	$num = rand() % 33;
105
	$tmp = substr($salt, $num, 1);
106
	$new_pass = $new_pass . $tmp;
107
	$i++;
108
}
109
$md5_password = md5($new_pass);
110
111
// Check if username already exists
112
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
113
if($results->numRows() > 0) {
114
	$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
115
}
116
117
// Check if the email already exists
118
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'");
119
if($results->numRows() > 0) {
120
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
121
		$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
122
	} else {
123
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
124
	}
125
}
126
127
// MD5 supplied password
128
$md5_password = md5($new_pass);
129
130
// Inser the user into the database
131
$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')";
132
$database->query($query);
133
134
if($database->is_error()) {
135
	// Error updating database
136
	$message = $database->get_error();
137
} else {
138
	// Setup email to send
139
	$mail_to = $email;
140
	$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
141
142
	// Replace placeholders from language variable with values
143
	$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
144
	$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass);
145
	$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
146
147
	// Try sending the email
148
	if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
149
		$display_form = false;
150
		$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php');
151
	} else {
152
		$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
153
		$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
154
	}
155
}
156
157
?>