Project

General

Profile

1
<?php
2

    
3
// $Id: signup2.php 275 2006-01-14 21:50:48Z stefan $
4

    
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
	header('Location: ../pages/index.php');
28
}
29

    
30
require_once(WB_PATH.'/framework/class.wb.php');
31
$wb = new wb('Start', 'start', false, false);
32

    
33
// Create new database object
34
$database = new database();
35

    
36
// Get details entered
37
$group_id = FRONTEND_SIGNUP;
38
$active = 1;
39
$username = strtolower($wb->get_post('username'));
40
$display_name = $wb->get_post('display_name');
41
$email = $wb->get_post('email');
42

    
43
// Create a javascript back link
44
$js_back = "javascript: history.go(-1);";
45

    
46
// Check values
47
if($group_id == "") {
48
	$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
49
}
50
if(strlen($username) < 3) {
51
	$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false);
52
}
53
if($email != "") {
54
	if($wb->validate_email($email) == false) {
55
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
56
	}
57
} else {
58
	$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
59
}
60
// Captcha
61
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg') AND CAPTCHA_VERIFICATION) { /* Make's sure GD library is installed */
62
	if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
63
		// Check for a mismatch
64
		if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
65
			$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
66
		}
67
	} else {
68
		$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
69
	}
70
}
71
if(isset($_SESSION['catpcha'])) { unset($_SESSION['captcha']); }
72

    
73
// Generate a random password then update the database with it
74
$new_pass = '';
75
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
76
srand((double)microtime()*1000000);
77
$i = 0;
78
while ($i <= 7) {
79
	$num = rand() % 33;
80
	$tmp = substr($salt, $num, 1);
81
	$new_pass = $new_pass . $tmp;
82
	$i++;
83
}
84
$md5_password = md5($new_pass);
85

    
86
// Check if username already exists
87
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
88
if($results->numRows() > 0) {
89
	$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
90
}
91

    
92
// Check if the email already exists
93
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'");
94
if($results->numRows() > 0) {
95
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
96
		$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
97
	} else {
98
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
99
	}
100
}
101

    
102
// MD5 supplied password
103
$md5_password = md5($new_pass);
104

    
105
// Inser the user into the database
106
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,active,username,password,display_name,email) VALUES ('$group_id', '$active', '$username','$md5_password','$display_name','$email')";
107
$database->query($query);
108

    
109
if($database->is_error()) {
110
	// Error updating database
111
	$message = $database->get_error();
112
} else {
113
	// Setup email to send
114
	$mail_subject = 'Your login details...';
115
	$mail_to = $email;
116
	$mail_message = ''.
117
'Hello '.$display_name.', 
118

    
119
Your '.WEBSITE_TITLE.' login details are:
120
Username: '.$username.'
121
Password: '.$new_pass.'
122

    
123
Your password has been set to the one above.
124

    
125
If you have recieved this message in error, please delete it immediatly.';
126

    
127
	// Try sending the email
128
	if(mail($mail_to, $mail_subject, $mail_message, 'From: '.SERVER_EMAIL)) {
129
		$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login'.PAGE_EXTENSION);
130
		$display_form = false;
131
	} else {
132
		$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
133
	}
134
}
135

    
136
?>
(13-13/15)