1 |
1475
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package users
|
6 |
1529
|
Luisehahne
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7 |
1475
|
Luisehahne
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8 |
|
|
* @link http://www.websitebaker2.org/
|
9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
|
|
* @platform WebsiteBaker 2.8.x
|
11 |
|
|
* @requirements PHP 5.2.2 and higher
|
12 |
|
|
* @version $Id$
|
13 |
|
|
* @filesource $HeadURL$
|
14 |
|
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
1815
|
Luisehahne
|
/* -------------------------------------------------------- */
|
19 |
|
|
// Must include code to stop this file being accessed directly
|
20 |
|
|
if(!defined('WB_URL')) {
|
21 |
|
|
require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
|
22 |
|
|
throw new IllegalFileException();
|
23 |
|
|
}
|
24 |
|
|
/* -------------------------------------------------------- */
|
25 |
1475
|
Luisehahne
|
|
26 |
1815
|
Luisehahne
|
function add_user($admin, &$aActionRequest)
|
27 |
|
|
{
|
28 |
|
|
global $MESSAGE,$TEXT, $HEADING;
|
29 |
|
|
$database = WbDatabase::getInstance();
|
30 |
|
|
$bRetVal = false;
|
31 |
|
|
$iMinPassLength = 6;
|
32 |
1475
|
Luisehahne
|
|
33 |
1815
|
Luisehahne
|
if( !$admin->checkFTAN() )
|
34 |
|
|
{
|
35 |
|
|
// $admin->print_header();
|
36 |
|
|
msgQueue::add($MESSAGE['GENERIC_SECURITY_ACCESS']);
|
37 |
|
|
return $bRetVal;
|
38 |
|
|
}
|
39 |
1475
|
Luisehahne
|
|
40 |
1815
|
Luisehahne
|
// Get details entered
|
41 |
|
|
$groups_id = (isset($aActionRequest['groups'])) ? implode(",", $admin->add_slashes($aActionRequest['groups'])) : '';
|
42 |
|
|
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
|
43 |
|
|
$active = intval(strip_tags($admin->StripCodeFromText($aActionRequest['active'][0])));
|
44 |
|
|
$username_fieldname = strip_tags($admin->StripCodeFromText($aActionRequest['username_fieldname']));
|
45 |
|
|
$username = strtolower(strip_tags($admin->StripCodeFromText($aActionRequest[$username_fieldname])));
|
46 |
|
|
$password = strip_tags($admin->StripCodeFromText($aActionRequest['password']));
|
47 |
|
|
$password2 = strip_tags($admin->StripCodeFromText($aActionRequest['password2']));
|
48 |
|
|
$display_name = strip_tags($admin->StripCodeFromText($aActionRequest['display_name']));
|
49 |
|
|
$email = strip_tags($admin->StripCodeFromText($aActionRequest['email']));
|
50 |
|
|
$home_folder = strip_tags($admin->StripCodeFromText($aActionRequest['home_folder']));
|
51 |
1475
|
Luisehahne
|
|
52 |
1815
|
Luisehahne
|
$language = DEFAULT_LANGUAGE;
|
53 |
|
|
$timezone = -72000;
|
54 |
|
|
$date_format = DEFAULT_DATE_FORMAT;
|
55 |
|
|
$time_format = DEFAULT_TIME_FORMAT;
|
56 |
|
|
$confirm_code = '';
|
57 |
|
|
$confirm_timeout = 0;
|
58 |
|
|
$remember_key = '';
|
59 |
|
|
$login_ip = '';
|
60 |
|
|
$last_reset = 0;
|
61 |
|
|
$login_when = 0;
|
62 |
1475
|
Luisehahne
|
|
63 |
1815
|
Luisehahne
|
// Check values
|
64 |
|
|
// Check values
|
65 |
|
|
if($groups_id == "") {
|
66 |
|
|
msgQueue::add($MESSAGE['USERS_NO_GROUP']);
|
67 |
|
|
} else {
|
68 |
|
|
$aGroups_id = explode(',', $groups_id);
|
69 |
|
|
//if user is in administrator-group, get this group else just get the first one
|
70 |
|
|
if($admin->is_group_match($groups_id,'1')) { $group_id = 1; } else { $group_id = intval($aGroups_id[0]); }
|
71 |
|
|
}
|
72 |
1475
|
Luisehahne
|
|
73 |
1815
|
Luisehahne
|
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
|
74 |
|
|
msgQueue::add( $MESSAGE['USERS_NAME_INVALID_CHARS']);
|
75 |
|
|
}
|
76 |
1475
|
Luisehahne
|
|
77 |
1815
|
Luisehahne
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
|
78 |
|
|
'WHERE `username` LIKE \''.$username.'\' ';
|
79 |
|
|
// Check if username already exists
|
80 |
|
|
if( ($iFoundUser = $database->get_one($sql)) != null ) {
|
81 |
|
|
if($iFoundUser) {
|
82 |
|
|
msgQueue::add($MESSAGE['USERS_USERNAME_TAKEN']);
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
1475
|
Luisehahne
|
|
86 |
1815
|
Luisehahne
|
if(strlen($password) < $iMinPassLength ) {
|
87 |
|
|
msgQueue::add($MESSAGE['USERS_PASSWORD_TOO_SHORT']);
|
88 |
|
|
}
|
89 |
1475
|
Luisehahne
|
|
90 |
1815
|
Luisehahne
|
$pattern = '/[^'.$admin->password_chars.']/';
|
91 |
|
|
if (preg_match($pattern, $password)) {
|
92 |
|
|
msgQueue::add($MESSAGE['PREFERENCES_INVALID_CHARS']);
|
93 |
|
|
}
|
94 |
1475
|
Luisehahne
|
|
95 |
1815
|
Luisehahne
|
if(($password != $password2) ) {
|
96 |
|
|
msgQueue::add($MESSAGE['USERS_PASSWORD_MISMATCH']);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
//
|
100 |
|
|
// check that display_name is unique in whoole system (prevents from User-faking)
|
101 |
|
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` ';
|
102 |
|
|
$sql .= 'WHERE `user_id` <> '.(int)$admin->get_user_id().' AND `display_name` LIKE "'.$display_name.'"';
|
103 |
|
|
if( ($iFoundUser = intval($database->get_one($sql))) > 0 ){
|
104 |
|
|
msgQueue::add($MESSAGE['USERS_USERNAME_TAKEN'].' ('.$TEXT['DISPLAY_NAME'].')');
|
105 |
|
|
} else {
|
106 |
|
|
if($display_name == '') {
|
107 |
|
|
msgQueue::add($MESSAGE['GENERIC_FILL_IN_ALL'].' ('.$TEXT['DISPLAY_NAME'].')');
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
if(findStringInFileList($display_name, dirname(__FILE__).'/disallowedNames')) {
|
112 |
|
|
msgQueue::add( $TEXT['ERROR'].' '.$TEXT['DISPLAY_NAME'].' ('.$display_name.')' );
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
if($email != "")
|
116 |
|
|
{
|
117 |
|
|
if($admin->validate_email($email) == false)
|
118 |
|
|
{
|
119 |
|
|
msgQueue::add($MESSAGE['USERS_INVALID_EMAIL'].' ('.$email.')');
|
120 |
|
|
}
|
121 |
|
|
} else { // e-mail must be present
|
122 |
|
|
msgQueue::add($MESSAGE['SIGNUP_NO_EMAIL']);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
|
126 |
|
|
'WHERE `email` LIKE \''.$email.'\' ';
|
127 |
|
|
|
128 |
|
|
// Check if the email already exists
|
129 |
|
|
if( ($iFoundUser = $database->get_one($sql)) != null ) {
|
130 |
|
|
if($iFoundUser) {
|
131 |
|
|
if(isset($MESSAGE['USERS_EMAIL_TAKEN']))
|
132 |
|
|
{
|
133 |
|
|
msgQueue::add($MESSAGE['USERS_EMAIL_TAKEN'].' ('.$email.')');
|
134 |
|
|
} else {
|
135 |
|
|
msgQueue::add($MESSAGE['USERS_INVALID_EMAIL'].' ('.$email.')');
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
if( ($msg = msgQueue::getError()) == '')
|
141 |
|
|
{
|
142 |
|
|
//if user is in administrator-group, get this group else just get the first one
|
143 |
|
|
if($admin->is_group_match($groups_id,'1')) { $group_id = 1; $groups_id = '1'; }
|
144 |
|
|
// Inser the user into the database
|
145 |
|
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'users` SET '.
|
146 |
|
|
'`group_id` = '.intval($group_id).', '.
|
147 |
|
|
'`groups_id` = \''.mysql_real_escape_string($groups_id).'\', '.
|
148 |
|
|
'`active` = '.intval($active).', '.
|
149 |
|
|
'`username` = \''.mysql_real_escape_string($username).'\', '.
|
150 |
|
|
'`password` = \''.md5($password).'\', '.
|
151 |
|
|
'`confirm_code` = \''.mysql_real_escape_string($confirm_code).'\', '.
|
152 |
|
|
'`confirm_timeout` = '.intval($confirm_timeout).', '.
|
153 |
|
|
'`remember_key` = \''.mysql_real_escape_string($remember_key).'\', '.
|
154 |
|
|
'`last_reset` = '.intval($last_reset).', '.
|
155 |
|
|
'`display_name` = \''.mysql_real_escape_string($display_name).'\', '.
|
156 |
|
|
'`email` = \''.mysql_real_escape_string($email).'\', '.
|
157 |
|
|
'`timezone` = '.intval($timezone).', '.
|
158 |
|
|
'`date_format` = \''.mysql_real_escape_string($date_format).'\', '.
|
159 |
|
|
'`time_format` = \''.mysql_real_escape_string($time_format).'\', '.
|
160 |
|
|
'`language` = \''.mysql_real_escape_string($language).'\', '.
|
161 |
|
|
'`home_folder` = \''.mysql_real_escape_string($home_folder).'\', '.
|
162 |
|
|
'`login_when` = '.intval($login_when).', '.
|
163 |
|
|
'`login_ip` = \''.mysql_real_escape_string($login_ip).'\' '.
|
164 |
|
|
'';
|
165 |
|
|
if($database->query($sql)) {
|
166 |
|
|
msgQueue::add($MESSAGE['USERS_ADDED'], true);
|
167 |
|
|
}
|
168 |
|
|
if($database->is_error()) {
|
169 |
|
|
msgQueue::add( implode('<br />',explode(';',$database->get_error())) );
|
170 |
|
|
}
|
171 |
|
|
} else {
|
172 |
|
|
msgQueue::add($HEADING['ADD_USER'].' '.$MESSAGE['GENERIC_NOT_COMPARE']);
|
173 |
|
|
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
//
|