Project

General

Profile

1 4 ryan
<?php
2
3 17 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 310 ryan
 Copyright (C) 2004-2006, Ryan Djurovich
9 4 ryan
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 286 stefan
	exit(0);
29 4 ryan
}
30
31 275 stefan
require_once(WB_PATH.'/framework/class.wb.php');
32
$wb = new wb('Start', 'start', false, false);
33 253 ryan
34 4 ryan
// Create new database object
35
$database = new database();
36
37
// Get details entered
38
$group_id = FRONTEND_SIGNUP;
39
$active = 1;
40 275 stefan
$username = strtolower($wb->get_post('username'));
41
$display_name = $wb->get_post('display_name');
42
$email = $wb->get_post('email');
43 4 ryan
44
// Create a javascript back link
45
$js_back = "javascript: history.go(-1);";
46
47
// Check values
48
if($group_id == "") {
49 275 stefan
	$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
50 4 ryan
}
51
if(strlen($username) < 3) {
52 275 stefan
	$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false);
53 4 ryan
}
54
if($email != "") {
55 275 stefan
	if($wb->validate_email($email) == false) {
56
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
57 4 ryan
	}
58
} else {
59 275 stefan
	$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
60 4 ryan
}
61 253 ryan
// Captcha
62 266 ryan
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg') AND CAPTCHA_VERIFICATION) { /* Make's sure GD library is installed */
63 253 ryan
	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 275 stefan
			$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
67 253 ryan
		}
68
	} else {
69 275 stefan
		$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
70 253 ryan
	}
71
}
72 281 stefan
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
73 4 ryan
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 275 stefan
	$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
91 4 ryan
}
92
93
// Check if the email already exists
94 106 stefan
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'");
95 4 ryan
if($results->numRows() > 0) {
96
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
97 275 stefan
		$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
98 4 ryan
	} else {
99 275 stefan
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
100 4 ryan
	}
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,active,username,password,display_name,email) VALUES ('$group_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_subject = 'Your login details...';
116
	$mail_to = $email;
117
	$mail_message = ''.
118
'Hello '.$display_name.',
119
120
Your '.WEBSITE_TITLE.' login details are:
121
Username: '.$username.'
122
Password: '.$new_pass.'
123
124
Your password has been set to the one above.
125
126
If you have recieved this message in error, please delete it immediatly.';
127
128
	// Try sending the email
129 300 stefan
	if($wb->mail('From: '.SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
130 275 stefan
		$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login'.PAGE_EXTENSION);
131 4 ryan
		$display_form = false;
132
	} else {
133 275 stefan
		$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
134 323 stefan
		$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
135 4 ryan
	}
136
}
137
138 239 stefan
?>