| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
require_once(dirname(__FILE__) . '/include/common.php'); |
|---|
| 55 |
|
|---|
| 56 |
require_once('classes/User.php'); |
|---|
| 57 |
require_once('classes/Security.php'); |
|---|
| 58 |
require_once('classes/MainUI.php'); |
|---|
| 59 |
require_once('classes/Mail.php'); |
|---|
| 60 |
$smarty = SmartyWifidog::getObject(); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
if (defined("CUSTOM_SIGNUP_URL")) { |
|---|
| 65 |
header("Location: " . CUSTOM_SIGNUP_URL . "?gw=" . base64_encode($_SERVER['REQUEST_URI'])); |
|---|
| 66 |
exit; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
function validate_username($username) |
|---|
| 80 |
{ |
|---|
| 81 |
if (!isset ($username) || !$username) { |
|---|
| 82 |
throw new Exception(_('Username is required.')); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
if (!ereg("^[0-9a-zA-Z_]*$", $username)) { |
|---|
| 86 |
throw new Exception(_('Username contains invalid characters.')); |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
function validate_email($email) |
|---|
| 102 |
{ |
|---|
| 103 |
if (!isset ($email) || !$email) { |
|---|
| 104 |
throw new Exception(_("A valid email address is required.")); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
if (Mail::validateEmailAddress($email) === false) { |
|---|
| 108 |
throw new Exception(_("The email address must be valid (i.e. user@domain.com). Please understand that we also black-listed various temporary-email-address providers.")); |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
function validate_passwords($password, $password_again) |
|---|
| 125 |
{ |
|---|
| 126 |
if (!isset ($password) || !$password) { |
|---|
| 127 |
throw new Exception(_("A password of at least 6 characters is required.")); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
if (!ereg("^[0-9a-zA-Z]*$", $password)) { |
|---|
| 131 |
throw new Exception(_("Password contains invalid characters. Allowed characters are 0-9, a-z and A-Z")); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
if (!isset ($password_again)) { |
|---|
| 135 |
throw new Exception(_("You must type your password twice.")); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
if ($password != $password_again) { |
|---|
| 139 |
throw new Exception(_("Passwords do not match.")); |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
if (strlen($password) < 6) { |
|---|
| 143 |
throw new Exception(_("Password is too short, it must be 6 characters minimum.")); |
|---|
| 144 |
} |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
$smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 153 |
$smarty->assign('sectionMAINCONTENT', false); |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
$smarty->assign('username', ""); |
|---|
| 157 |
$smarty->assign('email', ""); |
|---|
| 158 |
$smarty->assign('error', ""); |
|---|
| 159 |
$smarty->assign('auth_sources', ""); |
|---|
| 160 |
$smarty->assign('selected_auth_source', ""); |
|---|
| 161 |
$smarty->assign('SelectNetworkUI', ""); |
|---|
| 162 |
|
|---|
| 163 |
if (isset ($_REQUEST["form_request"]) && $_REQUEST["form_request"] == "signup") { |
|---|
| 164 |
|
|---|
| 165 |
$username = trim($_REQUEST['username']); |
|---|
| 166 |
$email = trim($_REQUEST['email']); |
|---|
| 167 |
$password = trim($_REQUEST['password']); |
|---|
| 168 |
$password_again = trim($_REQUEST['password_again']); |
|---|
| 169 |
|
|---|
| 170 |
$smarty->assign('username', $username); |
|---|
| 171 |
$smarty->assign('email', $email); |
|---|
| 172 |
|
|---|
| 173 |
$network = Network::getObject($_REQUEST['auth_source']); |
|---|
| 174 |
|
|---|
| 175 |
try { |
|---|
| 176 |
|
|---|
| 177 |
* Tool content |
|---|
| 178 |
*/ |
|---|
| 179 |
|
|---|
| 180 |
// Set section of Smarty template |
|---|
| 181 |
$smarty->assign('sectionTOOLCONTENT', true); |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
$html = $smarty->fetch("templates/sites/manual_useradd.tpl"); |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
* Main content |
|---|
| 188 |
*/ |
|---|
| 189 |
|
|---|
| 190 |
// Reset ALL smarty SWITCH values |
|---|
| 191 |
$smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 192 |
$smarty->assign('sectionMAINCONTENT', false); |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
$smarty->assign('sectionMAINCONTENT', true); |
|---|
| 196 |
|
|---|
| 197 |
if (!isset($network)) { |
|---|
| 198 |
throw new Exception(_("Sorry, this network does not exist !")); |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
validate_username($username); |
|---|
| 203 |
validate_email($email); |
|---|
| 204 |
validate_passwords($password, $password_again); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
if (User::getUserByUsernameAndOrigin($username, $network)) { |
|---|
| 208 |
throw new Exception(_("Sorry, a user account is already associated to this username. Pick another one.")); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
if (User::getUserByEmailAndOrigin($email, $network)) { |
|---|
| 212 |
throw new Exception(_("Sorry, a user account is already associated to this email address.")); |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
$tempguid = get_guid(); |
|---|
| 217 |
$created_user = User::createUser($tempguid, $username, $network, $email, $password); |
|---|
| 218 |
|
|---|
| 219 |
$validated_user = User::getObject($tempguid); |
|---|
| 220 |
|
|---|
| 221 |
$validated_user->SetAccountStatus(ACCOUNT_STATUS_ALLOWED); |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
$html_body = $smarty->fetch("templates/sites/manual_useradd.tpl"); |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
* Render output |
|---|
| 228 |
*/ |
|---|
| 229 |
|
|---|
| 230 |
$usercomplete = "User: $username has been added!"; |
|---|
| 231 |
|
|---|
| 232 |
$ui = MainUI::getObject(); |
|---|
| 233 |
|
|---|
| 234 |
$ui->addContent('left_area_middle', $html); |
|---|
| 235 |
$ui->addContent('main_area_middle', $html_body); |
|---|
| 236 |
|
|---|
| 237 |
$ui->addContent('main_area_top', $usercomplete); |
|---|
| 238 |
|
|---|
| 239 |
$ui->display(); |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
exit; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
catch (Exception $e) { |
|---|
| 246 |
$smarty->assign('error', $e->getMessage()); |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
$html = ""; |
|---|
| 250 |
$html_body = ""; |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
$smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 254 |
$smarty->assign('sectionMAINCONTENT', false); |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
if (isset ($_REQUEST["form_request"]) && $_REQUEST["form_request"] == "login") { |
|---|
| 263 |
$username = trim($_REQUEST['username']); |
|---|
| 264 |
if (strpos($username, "@") === false) |
|---|
| 265 |
$smarty->assign('username', $username); |
|---|
| 266 |
else { |
|---|
| 267 |
$email = $username; |
|---|
| 268 |
$username = ""; |
|---|
| 269 |
$smarty->assign('email', $email); |
|---|
| 270 |
} |
|---|
| 271 |
} |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
$smarty->assign('sectionTOOLCONTENT', true); |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
$html = $smarty->fetch("templates/sites/manual_useradd.tpl"); |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
$smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 285 |
$smarty->assign('sectionMAINCONTENT', false); |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
$smarty->assign('sectionMAINCONTENT', true); |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
$sources = array (); |
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
$network_array = Network::getAllNetworks(); |
|---|
| 295 |
|
|---|
| 296 |
foreach ($network_array as $network) { |
|---|
| 297 |
if ($network->getAuthenticator()->isRegistrationPermitted()) { |
|---|
| 298 |
$sources[$network->getId()] = $network->getName(); |
|---|
| 299 |
} |
|---|
| 300 |
} |
|---|
| 301 |
|
|---|
| 302 |
if (isset($sources)) { |
|---|
| 303 |
$smarty->assign('auth_sources', $sources); |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
if (isset($_REQUEST["auth_source"])) { |
|---|
| 308 |
$smarty->assign('selected_auth_source', $_REQUEST["auth_source"]); |
|---|
| 309 |
} |
|---|
| 310 |
|
|---|
| 311 |
$smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
$html_body = $smarty->fetch("templates/sites/manual_useradd.tpl"); |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
$ui = MainUI::getObject(); |
|---|
| 320 |
$ui->addContent('left_area_middle', $html); |
|---|
| 321 |
$ui->addContent('main_area_middle', $html_body); |
|---|
| 322 |
$ui->display(); |
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
?> |
|---|
| 333 |
|
|---|