Revision 1262
Added by Dietmar almost 15 years ago
signup2.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, 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 |
exit(0); |
|
29 |
} |
|
30 |
|
|
31 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
32 |
$wb = new wb('Start', 'start', false, false); |
|
33 |
|
|
34 |
// Create new database object |
|
35 |
$database = new database(); |
|
36 |
|
|
37 |
// Get details entered |
|
38 |
$groups_id = FRONTEND_SIGNUP; |
|
39 |
$active = 1; |
|
40 |
$username = strtolower(strip_tags($wb->get_post_escaped('username'))); |
|
41 |
$display_name = strip_tags($wb->get_post_escaped('display_name')); |
|
42 |
$email = $wb->get_post('email'); |
|
43 |
|
|
44 |
// Create a javascript back link |
|
45 |
$js_back = "javascript: history.go(-1);"; |
|
46 |
|
|
47 |
// Check values |
|
48 |
if($groups_id == "") { |
|
49 |
$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false); |
|
50 |
} |
|
51 |
if(strlen($username) < 3) { |
|
52 |
$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false); |
|
53 |
} |
|
54 |
if($email != "") { |
|
55 |
if($wb->validate_email($email) == false) { |
|
56 |
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false); |
|
57 |
} |
|
58 |
} else { |
|
59 |
$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false); |
|
60 |
} |
|
61 |
|
|
62 |
$email = $wb->add_slashes($email); |
|
63 |
|
|
64 |
// Captcha |
|
65 |
if(ENABLED_CAPTCHA) { |
|
66 |
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){ |
|
67 |
// Check for a mismatch |
|
68 |
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) { |
|
69 |
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false); |
|
70 |
} |
|
71 |
} else { |
|
72 |
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false); |
|
73 |
} |
|
74 |
} |
|
75 |
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); } |
|
76 |
|
|
77 |
// Generate a random password then update the database with it |
|
78 |
$new_pass = ''; |
|
79 |
$salt = "abchefghjkmnpqrstuvwxyz0123456789"; |
|
80 |
srand((double)microtime()*1000000); |
|
81 |
$i = 0; |
|
82 |
while ($i <= 7) { |
|
83 |
$num = rand() % 33; |
|
84 |
$tmp = substr($salt, $num, 1); |
|
85 |
$new_pass = $new_pass . $tmp; |
|
86 |
$i++; |
|
87 |
} |
|
88 |
$md5_password = md5($new_pass); |
|
89 |
|
|
90 |
// Check if username already exists |
|
91 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'"); |
|
92 |
if($results->numRows() > 0) { |
|
93 |
$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false); |
|
94 |
} |
|
95 |
|
|
96 |
// Check if the email already exists |
|
97 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'"); |
|
98 |
if($results->numRows() > 0) { |
|
99 |
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) { |
|
100 |
$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false); |
|
101 |
} else { |
|
102 |
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
// MD5 supplied password |
|
107 |
$md5_password = md5($new_pass); |
|
108 |
|
|
109 |
// Inser the user into the database |
|
110 |
$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')"; |
|
111 |
$database->query($query); |
|
112 |
|
|
113 |
if($database->is_error()) { |
|
114 |
// Error updating database |
|
115 |
$message = $database->get_error(); |
|
116 |
} else { |
|
117 |
// Setup email to send |
|
118 |
$mail_to = $email; |
|
119 |
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO']; |
|
120 |
|
|
121 |
// Replace placeholders from language variable with values |
|
122 |
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}'); |
|
123 |
$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass); |
|
124 |
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']); |
|
125 |
|
|
126 |
// Try sending the email |
|
127 |
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { |
|
128 |
$display_form = false; |
|
129 |
$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php'); |
|
130 |
} else { |
|
131 |
$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'"); |
|
132 |
$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
?> |
|
1 |
<?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 |
* @author Ryan Djurovich |
|
35 |
* @copyright 2004-2009, Ryan Djurovich |
|
36 |
* @copyright 2009-2010, Website Baker Org. e.V. |
|
37 |
* @filesource $HeadURL$ |
|
38 |
* @author Ryan Djurovich |
|
39 |
* @copyright 2004-2009, Ryan Djurovich |
|
40 |
* |
|
41 |
* @author WebsiteBaker Project |
|
42 |
* @link http://www.websitebaker2.org/ |
|
43 |
* @copyright 2009-2010, Website Baker Org. e.V. |
|
44 |
* @link http://start.websitebaker2.org/impressum-datenschutz.php |
|
45 |
* @license http://www.gnu.org/licenses/gpl.html |
|
46 |
* @version $Id$ |
|
47 |
* @platform WebsiteBaker 2.8.x |
|
48 |
* @requirements PHP 4.3.4 and higher |
|
49 |
* @lastmodified $Date$ |
|
50 |
* |
|
51 |
*/ |
|
52 |
|
|
53 |
if(!defined('WB_URL')) { |
|
54 |
header('Location: ../pages/index.php'); |
|
55 |
exit(0); |
|
56 |
} |
|
57 |
|
|
58 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
59 |
$wb = new wb('Start', 'start', false, false); |
|
60 |
|
|
61 |
// Create new database object |
|
62 |
$database = new database(); |
|
63 |
|
|
64 |
// Get details entered |
|
65 |
$groups_id = FRONTEND_SIGNUP; |
|
66 |
$active = 1; |
|
67 |
$username = strtolower(strip_tags($wb->get_post_escaped('username'))); |
|
68 |
$display_name = strip_tags($wb->get_post_escaped('display_name')); |
|
69 |
$email = $wb->get_post('email'); |
|
70 |
|
|
71 |
// Create a javascript back link |
|
72 |
$js_back = "javascript: history.go(-1);"; |
|
73 |
|
|
74 |
// Check values |
|
75 |
if($groups_id == "") { |
|
76 |
$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false); |
|
77 |
} |
|
78 |
if(strlen($username) < 3) { |
|
79 |
$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false); |
|
80 |
} |
|
81 |
if($email != "") { |
|
82 |
if($wb->validate_email($email) == false) { |
|
83 |
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false); |
|
84 |
} |
|
85 |
} else { |
|
86 |
$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false); |
|
87 |
} |
|
88 |
|
|
89 |
$email = $wb->add_slashes($email); |
|
90 |
|
|
91 |
// Captcha |
|
92 |
if(ENABLED_CAPTCHA) { |
|
93 |
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){ |
|
94 |
// Check for a mismatch |
|
95 |
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) { |
|
96 |
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false); |
|
97 |
} |
|
98 |
} else { |
|
99 |
$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false); |
|
100 |
} |
|
101 |
} |
|
102 |
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); } |
|
103 |
|
|
104 |
// Generate a random password then update the database with it |
|
105 |
$new_pass = ''; |
|
106 |
$salt = "abchefghjkmnpqrstuvwxyz0123456789"; |
|
107 |
srand((double)microtime()*1000000); |
|
108 |
$i = 0; |
|
109 |
while ($i <= 7) { |
|
110 |
$num = rand() % 33; |
|
111 |
$tmp = substr($salt, $num, 1); |
|
112 |
$new_pass = $new_pass . $tmp; |
|
113 |
$i++; |
|
114 |
} |
|
115 |
$md5_password = md5($new_pass); |
|
116 |
|
|
117 |
// Check if username already exists |
|
118 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'"); |
|
119 |
if($results->numRows() > 0) { |
|
120 |
$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false); |
|
121 |
} |
|
122 |
|
|
123 |
// Check if the email already exists |
|
124 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'"); |
|
125 |
if($results->numRows() > 0) { |
|
126 |
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) { |
|
127 |
$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false); |
|
128 |
} else { |
|
129 |
$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
// MD5 supplied password |
|
134 |
$md5_password = md5($new_pass); |
|
135 |
|
|
136 |
// Inser the user into the database |
|
137 |
$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')"; |
|
138 |
$database->query($query); |
|
139 |
|
|
140 |
if($database->is_error()) { |
|
141 |
// Error updating database |
|
142 |
$message = $database->get_error(); |
|
143 |
} else { |
|
144 |
// Setup email to send |
|
145 |
$mail_to = $email; |
|
146 |
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO']; |
|
147 |
|
|
148 |
// Replace placeholders from language variable with values |
|
149 |
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}'); |
|
150 |
$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass); |
|
151 |
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']); |
|
152 |
|
|
153 |
// Try sending the email |
|
154 |
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { |
|
155 |
$display_form = false; |
|
156 |
$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php'); |
|
157 |
} else { |
|
158 |
$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'"); |
|
159 |
$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
?> |
|
137 | 164 |
Also available in: Unified diff
Beginning header information update