Project

General

Profile

1
<?php
2

    
3
// $Id: signup2.php 253 2005-11-27 12:43:22Z ryan $
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.admin.php');
31
$admin = new admin('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($admin->get_post('username'));
40
$display_name = $admin->get_post('display_name');
41
$email = $admin->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
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
49
}
50
if(strlen($username) < 3) {
51
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
52
}
53
if($email != "") {
54
	if($admin->validate_email($email) == false) {
55
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
56
	}
57
} else {
58
	$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
59
}
60
// Captcha
61
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* 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
			$admin->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back);
66
		}
67
	} else {
68
		$admin->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back);
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
	$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
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
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
97
	} else {
98
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
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
		$admin->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login'.PAGE_EXTENSION);
130
		$display_form = false;
131
	} else {
132
		$admin->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back);
133
	}
134
}
135

    
136
?>
(13-13/15)