Revision 1475
Added by Dietmar over 13 years ago
add.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* |
|
4 |
* @category admin |
|
5 |
* @package users |
|
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$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
// Print admin header |
|
20 |
require('../../config.php'); |
|
21 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
22 |
// suppress to print the header, so no new FTAN will be set |
|
23 |
$admin = new admin('Access', 'users_add', false); |
|
24 |
|
|
25 |
// Create a javascript back link |
|
26 |
$js_back = ADMIN_URL.'/users/index.php'; |
|
27 |
|
|
28 |
if( !$admin->checkFTAN() ) |
|
29 |
{ |
|
30 |
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back); |
|
31 |
} |
|
32 |
// After check print the header |
|
33 |
$admin->print_header(); |
|
34 |
|
|
35 |
// Get details entered |
|
36 |
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : ''; //should check permissions |
|
37 |
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too |
|
38 |
$active = $admin->add_slashes($_POST['active'][0]); |
|
39 |
$username_fieldname = $admin->get_post_escaped('username_fieldname'); |
|
40 |
$username = strtolower($admin->get_post_escaped($username_fieldname)); |
|
41 |
$password = $admin->get_post('password'); |
|
42 |
$password2 = $admin->get_post('password2'); |
|
43 |
$display_name = $admin->get_post_escaped('display_name'); |
|
44 |
$email = $admin->get_post_escaped('email'); |
|
45 |
$home_folder = $admin->get_post_escaped('home_folder'); |
|
46 |
$default_language = DEFAULT_LANGUAGE; |
|
47 |
|
|
48 |
// Check values |
|
49 |
if($groups_id == '') { |
|
50 |
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back); |
|
51 |
} |
|
52 |
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) { |
|
53 |
$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '. |
|
54 |
$MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back); |
|
55 |
} |
|
56 |
if(strlen($password) < 2) { |
|
57 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back); |
|
58 |
} |
|
59 |
if($password != $password2) { |
|
60 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back); |
|
61 |
} |
|
62 |
if($email != '') |
|
63 |
{ |
|
64 |
if($admin->validate_email($email) == false) |
|
65 |
{ |
|
66 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back); |
|
67 |
} |
|
68 |
} else { // e-mail must be present |
|
69 |
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back); |
|
70 |
} |
|
71 |
|
|
72 |
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up) |
|
73 |
$gid_tmp = explode(',', $groups_id); |
|
74 |
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group |
|
75 |
else $group_id = $gid_tmp[0]; // else just get the first one |
|
76 |
unset($gid_tmp); |
|
77 |
|
|
78 |
// Check if username already exists |
|
79 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'"); |
|
80 |
if($results->numRows() > 0) { |
|
81 |
$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back); |
|
82 |
} |
|
83 |
|
|
84 |
// Check if the email already exists |
|
85 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'"); |
|
86 |
if($results->numRows() > 0) |
|
87 |
{ |
|
88 |
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) |
|
89 |
{ |
|
90 |
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back); |
|
91 |
} else { |
|
92 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
// MD5 supplied password |
|
97 |
$md5_password = md5($password); |
|
98 |
|
|
99 |
// Inser the user into the database |
|
100 |
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,home_folder,email,timezone, language) VALUES ('$group_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000', '$default_language')"; |
|
101 |
$database->query($query); |
|
102 |
if($database->is_error()) { |
|
103 |
$admin->print_error($database->get_error()); |
|
104 |
} else { |
|
105 |
$admin->print_success($MESSAGE['USERS']['ADDED']); |
|
106 |
} |
|
107 |
|
|
108 |
// Print admin footer |
|
109 |
$admin->print_footer(); |
|
110 |
|
|
111 |
|
|
1 |
<?php |
|
2 |
/** |
|
3 |
* |
|
4 |
* @category admin |
|
5 |
* @package users |
|
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$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
// Print admin header |
|
20 |
require('../../config.php'); |
|
21 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
22 |
// suppress to print the header, so no new FTAN will be set |
|
23 |
$admin = new admin('Access', 'users_add',false); |
|
24 |
|
|
25 |
// Create a javascript back link |
|
26 |
$js_back = ADMIN_URL.'/users/index.php'; |
|
27 |
|
|
28 |
if( !$admin->checkFTAN() ) |
|
29 |
{ |
|
30 |
$admin->print_header(); |
|
31 |
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back); |
|
32 |
} |
|
33 |
// After check print the header |
|
34 |
$admin->print_header(); |
|
35 |
|
|
36 |
// Get details entered |
|
37 |
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : ''; //should check permissions |
|
38 |
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too |
|
39 |
$active = $admin->add_slashes($_POST['active'][0]); |
|
40 |
$username_fieldname = $admin->get_post_escaped('username_fieldname'); |
|
41 |
$username = strtolower($admin->get_post_escaped($username_fieldname)); |
|
42 |
$password = $admin->get_post('password'); |
|
43 |
$password2 = $admin->get_post('password2'); |
|
44 |
$display_name = $admin->get_post_escaped('display_name'); |
|
45 |
$email = $admin->get_post_escaped('email'); |
|
46 |
$home_folder = $admin->get_post_escaped('home_folder'); |
|
47 |
$default_language = DEFAULT_LANGUAGE; |
|
48 |
|
|
49 |
// Check values |
|
50 |
if($groups_id == '') { |
|
51 |
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back); |
|
52 |
} |
|
53 |
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) { |
|
54 |
$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '. |
|
55 |
$MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back); |
|
56 |
} |
|
57 |
if(strlen($password) < 2) { |
|
58 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back); |
|
59 |
} |
|
60 |
if($password != $password2) { |
|
61 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back); |
|
62 |
} |
|
63 |
if($email != '') |
|
64 |
{ |
|
65 |
if($admin->validate_email($email) == false) |
|
66 |
{ |
|
67 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back); |
|
68 |
} |
|
69 |
} else { // e-mail must be present |
|
70 |
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back); |
|
71 |
} |
|
72 |
|
|
73 |
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up) |
|
74 |
$gid_tmp = explode(',', $groups_id); |
|
75 |
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group |
|
76 |
else $group_id = $gid_tmp[0]; // else just get the first one |
|
77 |
unset($gid_tmp); |
|
78 |
|
|
79 |
// Check if username already exists |
|
80 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'"); |
|
81 |
if($results->numRows() > 0) { |
|
82 |
$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back); |
|
83 |
} |
|
84 |
|
|
85 |
// Check if the email already exists |
|
86 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'"); |
|
87 |
if($results->numRows() > 0) |
|
88 |
{ |
|
89 |
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) |
|
90 |
{ |
|
91 |
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back); |
|
92 |
} else { |
|
93 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
// MD5 supplied password |
|
98 |
$md5_password = md5($password); |
|
99 |
|
|
100 |
// Inser the user into the database |
|
101 |
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,home_folder,email,timezone, language) VALUES ('$group_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000', '$default_language')"; |
|
102 |
$database->query($query); |
|
103 |
if($database->is_error()) { |
|
104 |
$admin->print_error($database->get_error()); |
|
105 |
} else { |
|
106 |
$admin->print_success($MESSAGE['USERS']['ADDED']); |
|
107 |
} |
|
108 |
|
|
109 |
// Print admin footer |
|
110 |
$admin->print_footer(); |
Also available in: Unified diff
! security fixes media, groups, users, sections
! reworked add sections in pages
! fix set empty href in show_menu2
! set show_menu2 version to 4.9.6
! reworked Droplet LoginBox, add redirect query
- remove unneeded folder js
! set Droplet to version 1.1.0
+ add checkboxes to change frontend absolute url to relative urls
! set output_filter version to 0.2