Project

General

Profile

1
<?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: signup2.php 1599 2012-02-06 15:59:24Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/signup2.php $
15
 * @lastmodified    $Date: 2012-02-06 16:59:24 +0100 (Mon, 06 Feb 2012) $
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
// require_once(WB_PATH.'/framework/class.wb.php');
23
$wb = new wb('Start', 'start', false, false);
24

    
25
// Get details entered
26
$groups_id = FRONTEND_SIGNUP;
27
$active = 1;
28
$username = strtolower(strip_tags($wb->get_post_escaped('username')));
29
$display_name = strip_tags($wb->get_post_escaped('display_name'));
30
$email = $wb->get_post('email');
31

    
32
// Create a javascript back link
33
$js_back = WB_URL.'/account/signup.php';
34
/*
35
if (!$wb->checkFTAN())
36
{
37
	$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back, false);
38
	exit();
39
}
40
*/
41
// Check values
42
if($groups_id == "") {
43
	$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
44
}
45
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
46
	$wb->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
47
	                  $MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
48
}
49
if($email != "") {
50
	if($wb->validate_email($email) == false) {
51
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
52
	}
53
} else {
54
	$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
55
}
56

    
57
$email = $wb->add_slashes($email);
58

    
59
// Captcha
60
if(ENABLED_CAPTCHA) {
61
	if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
62
		// Check for a mismatch
63
		if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
64
			$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
65
		}
66
	} else {
67
		$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
68
	}
69
}
70
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
71

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

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

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

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

    
104
// Inser the user into the database
105
$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')";
106
$database->query($query);
107

    
108
if($database->is_error()) {
109
	// Error updating database
110
	$message = $database->get_error();
111
} else {
112
	// Setup email to send
113
	$mail_to = $email;
114
	$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
115

    
116
	// Replace placeholders from language variable with values
117
	$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
118
	$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass); 
119
	$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
120

    
121
	// Try sending the email
122
	if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
123
		$display_form = false;
124
		$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php' );
125
	} else {
126
		$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
127
		$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
128
	}
129
}
130

    
(14-14/16)