Changeset 1401
- Timestamp:
- 07/03/09 12:21:22 (14 months ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 3 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/classes/Network.php (modified) (5 diffs)
-
wifidog/signup.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1399 r1401 1 1 # $Id$ 2 2009-07-03 Benoit Grégoire <benoitg@coeus.ca> 3 * Refactor signup.php. The code flow is still annoyingly unclear complex, but the file is shorter and hopefully easier to debug (and hopefully fixes #593) 4 2 5 2009-06-26 Benoit Grégoire <benoitg@coeus.ca> 3 6 * Updated greek translation by bill@e-texnologia.gr and strzol@gmail.com, still needs some work. -
trunk/wifidog-auth/wifidog/classes/Network.php
r1393 r1401 243 243 * objects to select 244 244 * $userData['allowEmpty'] boolean Allow not selecting any object 245 * $userData['onlyNetwoksAllowingSignup'] boolean Only list networks allowing user self-signup 245 246 * @return string HTML markup 246 247 … … 257 258 !empty($userData['nullCaptionString'])?$nullCaptionString=$userData['nullCaptionString']:$nullCaptionString=null; 258 259 !empty($userData['onChange'])?$onChangeString=$userData['onChange']:$onChangeString=""; 260 !empty($userData['onlyNetwoksAllowingSignup'])?$onlyNetwoksAllowingSignup=$userData['onlyNetwoksAllowingSignup']:$onlyNetwoksAllowingSignup=false; 259 261 260 262 $db = AbstractDb::getObject(); … … 270 272 $i = 0; 271 273 foreach ($network_rows as $network_row) { 272 $tab[$i][0] = $network_row['network_id']; 273 $tab[$i][1] = $network_row['name']; 274 $i ++; 274 275 if($onlyNetwoksAllowingSignup==false || (self::getObject($network_row['network_id'])->getAuthenticator()->isRegistrationPermitted())==true){ 276 $tab[$i][0] = $network_row['network_id']; 277 $tab[$i][1] = $network_row['name']; 278 $i ++; 279 } 275 280 } 276 281 $html .= _("Network:")." \n"; … … 371 376 $network_id_str = $db->escapeString($p_network_id); 372 377 if ($network_id_str == "") 373 $network_id_str = $db->escapeString(self::getDefaultNetwork()->getId());378 $network_id_str = $db->escapeString(self::getDefaultNetwork()->getId()); 374 379 375 380 $sql = "SELECT *, EXTRACT(EPOCH FROM validation_grace_time) as validation_grace_time_seconds FROM networks WHERE network_id='$network_id_str'"; … … 1423 1428 } 1424 1429 1425 /**1426 * Are nodes allowed to redirect users to the original requested web page instead of1427 * the portal?1428 *1429 * @return bool True or false1430 *1431 * @access public1432 */1433 public function getPortalOriginalUrlAllowed()1434 {1435 return (($this->_row['allow_original_url_redirect'] == 't') ? true : false);1436 }1437 1438 /**1439 * Set if nodes are allowed to redirect users to the original requested web page1440 * instead of the portal?1441 *1442 * @param bool $value The new value, true or false1443 *1444 * @return bool True on success, false on failure1445 *1446 * @access public1447 */1448 public function setPortalOriginalUrlAllowed($value)1449 {1450 // Init values1451 $retval = true;1452 1453 if ($value != $this->getPortalOriginalUrlAllowed()) {1454 $db = AbstractDb::getObject();1455 $value ? $value = 'TRUE' : $value = 'FALSE';1456 $retval = $db->execSqlUpdate("UPDATE networks SET allow_original_url_redirect = {$value} WHERE network_id = '{$this->getId()}'", false);1457 $this->refresh();1458 }1459 1460 return $retval;1461 }1430 /** 1431 * Are nodes allowed to redirect users to the original requested web page instead of 1432 * the portal? 1433 * 1434 * @return bool True or false 1435 * 1436 * @access public 1437 */ 1438 public function getPortalOriginalUrlAllowed() 1439 { 1440 return (($this->_row['allow_original_url_redirect'] == 't') ? true : false); 1441 } 1442 1443 /** 1444 * Set if nodes are allowed to redirect users to the original requested web page 1445 * instead of the portal? 1446 * 1447 * @param bool $value The new value, true or false 1448 * 1449 * @return bool True on success, false on failure 1450 * 1451 * @access public 1452 */ 1453 public function setPortalOriginalUrlAllowed($value) 1454 { 1455 // Init values 1456 $retval = true; 1457 1458 if ($value != $this->getPortalOriginalUrlAllowed()) { 1459 $db = AbstractDb::getObject(); 1460 $value ? $value = 'TRUE' : $value = 'FALSE'; 1461 $retval = $db->execSqlUpdate("UPDATE networks SET allow_original_url_redirect = {$value} WHERE network_id = '{$this->getId()}'", false); 1462 $this->refresh(); 1463 } 1464 1465 return $retval; 1466 } 1462 1467 1463 1468 -
trunk/wifidog-auth/wifidog/signup.php
r1399 r1401 42 42 * @author Max Horváth <max.horvath@freenet.de> 43 43 * @copyright 2004-2006 Philippe April 44 * @copyright 2004-200 6Benoit Grégoire, Technologies Coeus inc.44 * @copyright 2004-2009 Benoit Grégoire, Technologies Coeus inc. 45 45 * @copyright 2006 Max Horváth, Horvath Web Consulting 46 46 * @version Subversion $Id$ … … 147 147 * Process signing up 148 148 */ 149 150 // Init ALL smarty SWITCH values151 $smarty->assign('sectionTOOLCONTENT', false);152 $smarty->assign('sectionMAINCONTENT', false);153 149 154 150 // Init ALL smarty values … … 160 156 $smarty->assign('SelectNetworkUI', ""); 161 157 158 /* Signup was requested */ 162 159 if (isset ($_REQUEST["form_request"]) && $_REQUEST["form_request"] == "signup") { 163 // S ecureentered values160 // Sanitize user-entered values 164 161 $username = trim($_REQUEST['username']); 165 162 $email = trim($_REQUEST['email']); … … 170 167 $smarty->assign('email', $email); 171 168 172 $ network = Network::getObject($_REQUEST['auth_source']);169 $selectedNetwork = Network::getObject($_REQUEST['auth_source']); 173 170 174 171 try { … … 177 174 */ 178 175 179 // Set section ofSmarty template176 // Retrieve the TOOLCONTENT section of the Smarty template 180 177 $smarty->assign('sectionTOOLCONTENT', true); 181 182 // Compile HTML code 183 $html = $smarty->fetch("templates/sites/signup.tpl"); 178 $smarty->assign('sectionMAINCONTENT', false); 179 $htmlToolContent = $smarty->fetch("templates/sites/signup.tpl"); 184 180 185 181 /* … … 187 183 */ 188 184 189 // Reset ALL smarty SWITCH values 190 $smarty->assign('sectionTOOLCONTENT', false); 191 $smarty->assign('sectionMAINCONTENT', false); 192 193 // Set section of Smarty template 194 $smarty->assign('sectionMAINCONTENT', true); 195 196 if (!isset($network)) { 185 if (!isset($selectedNetwork)) { 197 186 throw new Exception(_("Sorry, this network does not exist !")); 198 187 } 199 188 200 if (!$ network->getAuthenticator()->isRegistrationPermitted()) {189 if (!$selectedNetwork->getAuthenticator()->isRegistrationPermitted()) { 201 190 throw new Exception(_("Sorry, this network does not accept new user registration !")); 202 191 } … … 208 197 209 198 // Check if user exists 210 if (User::getUserByUsernameAndOrigin($username, $ network)) {199 if (User::getUserByUsernameAndOrigin($username, $selectedNetwork)) { 211 200 throw new Exception(_("Sorry, a user account is already associated to this username. Pick another one.")); 212 201 } 213 202 214 if (User::getUserByEmailAndOrigin($email, $ network)) {203 if (User::getUserByEmailAndOrigin($email, $selectedNetwork)) { 215 204 throw new Exception(_("Sorry, a user account is already associated to this email address.")); 216 205 } 217 206 218 207 // Create user and send him the validation email 219 $created_user = User::createUser(get_guid(), $username, $ network, $email, $password);208 $created_user = User::createUser(get_guid(), $username, $selectedNetwork, $email, $password); 220 209 $created_user->sendValidationEmail(); 221 210 222 // Authenticate this new user automatically223 $errmsg = "";224 $authenticated_user = $network->getAuthenticator()->login($username, $password, $errmsg);225 226 // While in validation period, alert user that he should validate his account ASAP227 $validationMsgHtml = "<div id='warning_message_area'>\n";228 $validationMsgHtml .= _("An email with confirmation instructions was sent to your email address.");229 $validationMsgHtml .= sprintf(_("Your account has been granted %s minutes of access to retrieve your email and validate your account."), ($network->getValidationGraceTime() / 60));230 $validationMsgHtml .= _('You may now open a browser window or start your email client and go to any remote Internet address to obtain the validation email.');231 $validationMsgHtml .= "</div>\n";232 233 // If the user is at a REAL hotspot, give him his sign-up minutes right away234 $session = Session::getObject();211 // Authenticate this new user automatically 212 $errmsg = ""; 213 $authenticated_user = $selectedNetwork->getAuthenticator()->login($username, $password, $errmsg); 214 215 // While in validation period, alert user that he should validate his account ASAP 216 $validationMsgHtml = "<div id='warning_message_area'>\n"; 217 $validationMsgHtml .= _("An email with confirmation instructions was sent to your email address."); 218 $validationMsgHtml .= sprintf(_("Your account has been granted %s minutes of access to retrieve your email and validate your account."), ($selectedNetwork->getValidationGraceTime() / 60)); 219 $validationMsgHtml .= _('You may now open a browser window or start your email client and go to any remote Internet address to obtain the validation email.'); 220 $validationMsgHtml .= "</div>\n"; 221 222 // If the user is at a REAL hotspot, login the user and give him his sign-up minutes right away 223 $session = Session::getObject(); 235 224 $gw_id = $session->get(SESS_GW_ID_VAR); 236 225 $gw_address = $session->get(SESS_GW_ADDRESS_VAR); … … 247 236 } 248 237 249 MainUI::redirect($redirURL, 0); 250 } 251 238 MainUI::redirect($redirURL, 0); 239 } 240 // Set section of Smarty template 241 $smarty->assign('sectionTOOLCONTENT', false); 242 $smarty->assign('sectionMAINCONTENT', true); 252 243 // Compile HTML code 253 $html _body= $smarty->fetch("templates/sites/signup.tpl");244 $htmlMainContent = $smarty->fetch("templates/sites/signup.tpl"); 254 245 255 246 /* 256 * Render output 247 * Render output (siggess message) 257 248 */ 258 249 $ui = MainUI::getObject(); 259 250 260 $ui->addContent('left_area_middle', $html );261 $ui->addContent('main_area_middle', $html _body);262 263 // $ui->addContent('page_header', $validationMsgHtml);264 $ui->addContent('main_area_top', $validationMsgHtml);251 $ui->addContent('left_area_middle', $htmlToolContent); 252 $ui->addContent('main_area_middle', $htmlMainContent); 253 254 // $ui->addContent('page_header', $validationMsgHtml); 255 $ui->addContent('main_area_top', $validationMsgHtml); 265 256 266 257 $ui->display(); … … 269 260 exit; 270 261 } 271 272 262 catch (Exception $e) { 273 263 $smarty->assign('error', $e->getMessage()); 274 264 275 265 // Reset HTML output 276 $html = ""; 277 $html_body = ""; 278 279 // Reset ALL smarty SWITCH values 280 $smarty->assign('sectionTOOLCONTENT', false); 281 $smarty->assign('sectionMAINCONTENT', false); 266 $htmlToolContent = ""; 267 $htmlMainContent = ""; 282 268 } 283 269 } … … 287 273 */ 288 274 289 if (isset ($_REQUEST["form_request"]) && $_REQUEST["form_request"] == "login") {290 $username = trim($_REQUEST['username']);291 if (strpos($username, "@") === false)292 $smarty->assign('username', $username);293 else {294 $email = $username;295 $username = "";296 $smarty->assign('email', $email);297 }298 }299 300 275 // Set section of Smarty template 301 276 $smarty->assign('sectionTOOLCONTENT', true); 277 $smarty->assign('sectionMAINCONTENT', false); 302 278 303 279 // Compile HTML code 304 $html = $smarty->fetch("templates/sites/signup.tpl");280 $htmlToolContent = $smarty->fetch("templates/sites/signup.tpl"); 305 281 306 282 /* … … 308 284 */ 309 285 310 // Reset ALL smarty SWITCH values 286 // Use the account_origin along, if it was set (it may be set in case there was an error processing the form). 287 if (isset($_REQUEST["auth_source"])) { 288 $selectedNetwork = Network::getObject($_REQUEST['auth_source']); 289 } 290 else { 291 $selectedNetwork = Network::getDefaultNetwork(); 292 } 293 294 if (Server::getServer()->getUseGlobalUserAccounts()){ 295 $smarty->assign('SelectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='".$selectedNetwork->getId()."' />"); 296 } 297 else { 298 //Make sure to only list networks whose authenticator allows user self-signup 299 $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source', array('preSelectedObject' => $selectedNetwork, 'onlyNetwoksAllowingSignup' => true)) ); 300 } 301 302 // Set section of Smarty template 311 303 $smarty->assign('sectionTOOLCONTENT', false); 312 $smarty->assign('sectionMAINCONTENT', false);313 314 // Set section of Smarty template315 304 $smarty->assign('sectionMAINCONTENT', true); 316 317 // Add the auth servers list to smarty variables318 $sources = array ();319 320 // Preserve keys321 $network_array = Network::getAllNetworks();322 $default_network = Network::getDefaultNetwork();323 324 foreach ($network_array as $networkObject) {325 if ($networkObject->getAuthenticator()->isRegistrationPermitted()) {326 $sources[$networkObject->getId()] = $networkObject->getName();327 }328 }329 330 if (isset($sources)) {331 $smarty->assign('auth_sources', $sources);332 }333 334 // Pass the account_origin along, if it's set335 if (isset($_REQUEST["auth_source"])) {336 $smarty->assign('selected_auth_source', $_REQUEST["auth_source"]);337 }338 339 if (Server::getServer()->getUseGlobalUserAccounts())340 $smarty->assign('SelectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='".$default_network->getId()."' />");341 else342 $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source', array('preSelectedObject' => $network)) );343 344 305 // Compile HTML code 345 $html _body= $smarty->fetch("templates/sites/signup.tpl");306 $htmlMainContent = $smarty->fetch("templates/sites/signup.tpl"); 346 307 347 308 /* 348 * Render output309 * Render final output 349 310 */ 350 311 $ui = MainUI::getObject(); 351 $ui->addContent('left_area_middle', $html );352 $ui->addContent('main_area_middle', $html _body);312 $ui->addContent('left_area_middle', $htmlToolContent); 313 $ui->addContent('main_area_middle', $htmlMainContent); 353 314 $ui->display(); 354 315 … … 360 321 * End: 361 322 */ 362 363 ?>
