Changeset 1401 for trunk/wifidog-auth/wifidog/signup.php
- Timestamp:
- 07/03/09 12:21:22 (3 years ago)
- Files:
-
- 1 modified
-
trunk/wifidog-auth/wifidog/signup.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 ?>
