kenken999/php
0
1<?php2class RegisterPage extends RunnerPage3{4 public $pwdStrong = false;5 6 public $action;7 8 protected $regValues = array();9 10 protected $registerSuccess = false;11 12 protected $strUsername;13 protected $strPassword;14 protected $strEmail;15 16 protected $usernameFiled;17 protected $emailFiled;18 19 protected $prepActivationCode = "";20 21 protected $sendActivationLink = false;22 23 protected $sendActivationLinkFailedMessage = "";24 25 function __construct(&$params = "")26 {27 parent::__construct($params);28 29 $this->usernameFiled = Security::usernameField();30 $this->emailFiled = GetEmailField();31 32 if( GetGlobalData("userRequireActivation") ) {33 $this->sendActivationLink = true;34 }35 36 // fill global password settings37 $this->pwdStrong = GetGlobalData("pwdStrong", false);38 if( $this->pwdStrong )39 {40 $this->settingsMap["globalSettings"]["pwdLen"] = GetGlobalData("pwdLen", 0);41 $this->settingsMap["globalSettings"]["pwdUnique"] = GetGlobalData("pwdUnique", 0);42 $this->settingsMap["globalSettings"]["pwdDigits"] = GetGlobalData("pwdDigits", 0);43 $this->settingsMap["globalSettings"]["pwdStrong"] = true;44 $this->settingsMap["globalSettings"]["pwdUpperLower"] = GetGlobalData("pwdUpperLower", false);45 }46 47 $this->headerForms = array( "top" );48 $this->footerForms = array( "below-grid" );49 50 if ( $this->isMultistepped() )51 $this->bodyForms = array( "above-grid", "steps" );52 else53 $this->bodyForms = array( "above-grid", "grid" );54 }55 56 /**57 * Set the connection property58 */59 protected function setTableConnection()60 {61 global $cman;62 $this->connection = $cman->getForLogin();63 }64 65 /**66 * Set the 'cipherer' property67 */68 protected function assignCipherer()69 {70 $this->cipherer = new RunnerCipherer( $this->tName );71 }72 73 protected function setDataSource() {74 $this->dataSource = getLoginDataSource();75 } 76 77 /**78 * Activate user by email link79 */80 protected function activateNewUser()81 {82 $username = base64_decode( @$_GET["u"] );83 $code = @$_GET["code"];84 $usernameCondition = DataCondition::FieldEquals( 85 Security::usernameField(), 86 $username, 87 0, 88 Security::caseInsensitiveUsername() ? dsCASE_INSENSITIVE : dsCASE_STRICT 89 );90 91 $dc = new DsCommand();92 $dc->filter = $usernameCondition;93 94 $rs = $this->dataSource->getSingle( $dc ); 95 if( !$rs ) {96 echo "Invalid validation code.";97 return;98 }99 100 $data = $this->dataSource->decryptRecord( $rs->fetchAssoc() );101 102 if( !$data )103 {104 echo "Invalid validation code.";105 return;106 }107 108 $dbPassword = $data[ Security::passwordField() ];109 if( !Security::verifyActivationCode( $code, $username, $dbPassword ) )110 {111 echo "Invalid validation code.";112 return;113 }114 115 $dcUpdate = new DsCommand();116 $dcUpdate->values[ GetGlobalData("userActivationField") ] = 1;117 $dcUpdate->filter = $usernameCondition;118 119 $this->dataSource->updateSingle( $dcUpdate, false );120 121 $sessionLevel = Security::userSessionLevel();122 if( $sessionLevel === LOGGED_ACTIVATION_PENDING ) {123 // verify if 2factor activation needed124 $twofSettings =& Security::twoFactorSettings();125 if( $twofSettings["available"] && ( $twofSettings["required"] || $twofSettings["enable"] ) ) {126 Security::elevateSession( LOGGED_2FSETUP_PENDING );127 }128 else {129 Security::elevateSession();130 Security::auditLoginSuccess();131 Security::callAfterLogin();132 }133 $sessionLevel = Security::userSessionLevel();134 }135 136 137 $this->switchToSuccessPage();138 139 $this->hideItemType('register_activate_message');140 $this->body["begin"].= "<form method=\"POST\" action=\"".GetTableLink("login")."\" name=\"loginform\">141 <input type=\"Hidden\" name=\"username\" value=\"".runner_htmlspecialchars($username)."\">";142 $this->body["begin"].= "</form>";143 144 $onClick = "";145 if( $sessionLevel === LOGGED_2FSETUP_PENDING ) {146 $continueUrl = GetTableLink("userinfo");147 } else if( $sessionLevel === LOGGED_FULL ) {148 // probably landing page instead of menu149 $continueUrl = GetTableLink("menu");150 } else {151 $continueUrl = GetTableLink("login");152 $onClick = 'onclick="document.forms.loginform.submit();return false;"';153 }154 $this->xt->assign("body", $this->body);155 //$this->xt->assign("registered_block", true);156 $this->xt->assign("loginlink_attrs", 'href="' . $continueUrl . '" '.$onClick.' id="ProceedToLogin"');157 158 // display register_success page159 $this->display( $this->templatefile );160 }161 162 /**163 *164 */165 public function process()166 {167 global $globalEvents;168 169 // Before Process event170 if( $globalEvents->exists("BeforeProcessRegister") )171 $globalEvents->BeforeProcessRegister( $this );172 173 if( $this->action == "activate" && GetGlobalData("userRequireActivation") ) {174 return $this->activateNewUser();175 }176 177 if( $this->action == "Register" )178 {179 $this->registerSuccess = $this->registerNewUser();180 $this->doAfterRegistrationEvent();181 182 if( !$this->registerSuccess && $this->mode == REGISTER_POPUP )183 {184 $returnJSON = array();185 $returnJSON['success'] = false;186 187 if( strlen( $this->message ) )188 $returnJSON['message'] = $this->message;189 190 if( !$this->isCaptchaOk )191 $returnJSON['wrongCaptchaFieldName'] = $this->getCaptchaFieldName();192 193 echo printJSON( $returnJSON );194 exit();195 }196 }197 198 // proccess captcha199 if( $this->captchaExists() )200 $this->displayCaptcha();201 202 if( !$this->registerSuccess )203 {204 $this->prepareEditControls();205 $this->prepareSteps();206 $this->prepareReadonlyFields();207 }208 209 210 if( $this->registerSuccess && !$this->sendActivationLink || !$this->registerSuccess )211 {212 $this->addCommonJs();213 $this->fillSetCntrlMaps();214 $this->addButtonHandlers();215 }216 217 if( $this->registerSuccess )218 {219 $this->tryLoginNewUser();220 $this->pageName = $this->pSet->getDefaultPage( $this->successPageType() );221 $this->pSet = new ProjectSettings( $this->tName, $this->pageType, $this->pageName, GLOBAL_PAGES );222 $this->xt->assign("supertop_block", true);223 $this->pageData["buttons"] = array_merge( $this->pageData["buttons"], $this->pSet->buttons() );224 foreach( $this->pSet->buttons() as $b ) {225 $this->AddJSFile( "include/button_".$b.".js" );226 }227 }228 229 $this->doCommonAssignments();230 231 $this->showPage();232 }233 234 function addCommonJs() {235 parent::addCommonJs();236 237 // users table pSet238 $pSet = new ProjectSettings( $this->tName, $this->pageType, $this->pageName );239 if( $pSet->isAddPageEvents() )240 $this->AddJSFile("include/runnerJS/events/pageevents_".GetTableURL( $this->tName ).".js");241 }242 243 /**244 * Run after registration event245 */246 protected function doAfterRegistrationEvent()247 {248 global $globalEvents;249 250 if( $this->registerSuccess && $globalEvents->exists("AfterSuccessfulRegistration") )251 $globalEvents->AfterSuccessfulRegistration( $this->regValues, $this );252 253 if( !$this->registerSuccess && $globalEvents->exists("AfterUnsuccessfulRegistration") )254 $globalEvents->AfterUnsuccessfulRegistration( $this->regValues, $this->message, $this );255 }256 257 258 259 260 /**261 *262 */263 protected function registerNewUser()264 {265 global $globalEvents;266 267 $allow_registration = true;268 269 if ( !$this->checkCaptcha() )270 $allow_registration = false;271 272 $values = array();273 $blobfields = array();274 $filename_values = array();275 foreach( $this->pSet->getPageFields() as $uf )276 {277 $_control = $this->getControl( $uf, $this->id );;278 $_control->readWebValue($values, $blobfields, NULL, NULL, $filename_values);;279 }280 281 // add filenames to values282 foreach( $filename_values as $key => $value )283 {284 $values[ $key ] = $value;285 }286 287 if( GetGlobalData("userRequireActivation") ) {288 $values[ GetGlobalData("userActivationField") ] = 0;289 }290 291 $this->strUsername = $values[Security::usernameField()];292 $this->strPassword = $values[Security::passwordField()];293 if( Security::emailField() ) {294 $this->strEmail = $values[Security::emailField()];295 }296 $this->regValues = $values;297 298 if( !$this->checkRegisterData( $this->strUsername, $this->strPassword, $this->strEmail )299 || !$this->checkDeniedDuplicated( $values ) ) {300 $allow_registration = false;301 }302 303 $retval = $allow_registration;304 $sqlValues = array();305 if( $retval && $globalEvents->exists("BeforeRegister") )306 $retval = $globalEvents->BeforeRegister($values, $sqlValues, $this->message, $this);307 308 if( !$retval )309 return false;310 311 $originalpassword = $values[ Security::passwordField() ];312 313 // hash password314 if( GetGlobalData("bEncryptPasswords") && !$this->cipherer->isFieldEncrypted( Security::passwordField() ) ) {315 $values[ Security::passwordField() ] = Security::hashPassword( $originalpassword );316 }317 318 $dc = new DsCommand();319 $dc->values = &$values;320 $dc->advValues = array();321 foreach( $sqlValues as $field => $sqlValue ) {322 $dc->advValues[ $field ] = new DsOperand( dsotSQL, $sqlValue );323 } 324 325 $retval = $this->dataSource->insertSingle( $dc );326 327 if( GetGlobalData("userRequireActivation") ) {328 $this->prepActivationCode = Security::getActivationCode(329 $this->strUsername,330 $values[ Security::passwordField() ]331 );332 }333 334 $values[Security::passwordField()] = $originalpassword;335 336 if( !$retval ) {337 $this->setDatabaseError( $this->dataSource->lastError() );338 } else {339 $this->ProcessFiles(); 340 }341 342 return !!$retval;343 }344 345 /**346 * Check if the registration data is valid347 * @param String strUsername348 * @param String strPassword349 * @param String strEmail350 * @return Boolean351 */352 protected function checkRegisterData( $strUsername, $strPassword, $strEmail )353 {354 $ret = true;355 356 // check if entered username already exists357 if( !strlen($strUsername) )358 {359 $this->jsSettings['tableSettings'][ $this->tName ]['msg_userError'] = "Username can not be empty.";360 $ret = false;361 }362 else if( !$this->checkIfUsernameUnique( $strUsername ) )363 {364 $this->jsSettings['tableSettings'][ $this->tName ]['msg_userError'] = "Username"." <i>".runner_htmlspecialchars( $strUsername )."</i> "."already exists. Choose another username.";365 $ret = false;366 }367 368 if( Security::emailField() && $this->pSet->appearOnPage( Security::emailField() ) )369 {370 // check if entered email already exists371 if( !strlen($strEmail) )372 {373 $this->jsSettings['tableSettings'][ $this->tName ]['msg_emailError'] = "Please enter a valid email address.";374 $ret = false;375 }376 else if( !$this->checkIfEmailUnique( $strEmail ) )377 {378 $this->jsSettings['tableSettings'][ $this->tName ]['msg_emailError'] = "Email"." <i>". runner_htmlspecialchars( $strEmail )."</i> "."already registered. If you forgot your username or password use the password reminder form.";379 $ret = false;380 }381 }382 383 if( $this->pwdStrong )384 {385 if( !checkpassword( $strPassword ) )386 {387 $this->jsSettings['tableSettings'][ $this->tName ]['msg_passwordError'] = $this->getPwdStrongFailedMessage();388 $ret = false;389 }390 }391 392 return $ret;393 }394 395 396 /**397 * @return String398 */399 protected function getPwdStrongFailedMessage()400 {401 $msg = "";402 $pwdLen = GetGlobalData("pwdLen", 0);403 if($pwdLen)404 {405 $fmt = "Password must be at least %% characters length.";406 $fmt = str_replace("%%", "".$pwdLen, $fmt);407 $msg.= "<br>".$fmt;408 }409 $pwdUnique = GetGlobalData("pwdUnique", 0);410 if($pwdUnique)411 {412 $fmt = "Password must contain %% unique characters.";413 $fmt = str_replace("%%", "".$pwdUnique, $fmt);414 $msg.= "<br>".$fmt;415 }416 $pwdDigits = GetGlobalData("pwdDigits", 0);417 if($pwdDigits)418 {419 $fmt = "Password must contain %% digits or symbols.";420 $fmt = str_replace("%%", "".$pwdDigits, $fmt);421 $msg.= "<br>".$fmt;422 }423 if(GetGlobalData("pwdUpperLower", false))424 {425 $fmt = "Password must contain letters in upper and lower case.";426 $msg.= "<br>".$fmt;427 }428 429 if($msg)430 $msg = substr($msg, 4);431 432 return $msg;433 }434 435 /**436 * @param String strUsername437 * @return Boolean438 */439 protected function checkIfUsernameUnique( $strUsername )440 {441 if( $this->cipherer->isFieldEncrypted(Security::usernameField()) )442 $sUsername = $this->cipherer->MakeDBValue(Security::usernameField(), $strUsername, "", true);443 else444 $sUsername = add_db_quotes(Security::usernameField(), $strUsername);445 446 $strSQL = "select count(*) from ". $this->connection->addTableWrappers( Security::loginTable() )447 . " where " .448 $this->connection->comparisonSQL(449 $this->getFieldSQLDecrypt(Security::usernameField()),450 $sUsername,451 Security::caseInsensitiveUsername()452 );453 454 $data = $this->connection->query( $strSQL )->fetchNumeric();455 return $data[0] == 0;456 }457 458 /**459 * @param String strEmail460 * @return Boolean461 */462 protected function checkIfEmailUnique( $strEmail )463 {464 if( $this->cipherer->isFieldEncrypted(Security::emailField()) )465 $sEmail = $this->cipherer->MakeDBValue(Security::emailField(), $strEmail, "", true);466 else467 $sEmail = add_db_quotes(Security::emailField(), $strEmail);468 469 $strSQL = "select count(*) from ". $this->connection->addTableWrappers( Security::loginTable() )470 ." where ".471 $this->connection->comparisonSQL(472 $this->getFieldSQLDecrypt(Security::emailField()),473 $sEmail,474 true475 );476 477 $data = $this->connection->query( $strSQL )->fetchNumeric();478 return $data[0] == 0;479 }480 481 /**482 * Set values for the page's controls483 */484 protected function prepareEditControls()485 {486 $regFields = $this->pSet->getPageFields();487 488 if( !count($this->regValues) )489 {490 foreach( $regFields as $f )491 {492 $defaultValue = GetDefaultValue($f, PAGE_REGISTER, $this->tName );493 if( strlen($defaultValue) )494 $this->regValues[ $f ] = $defaultValue;495 }496 }497 498 foreach($regFields as $fName)499 {500 $gfName = GoodFieldName($fName);501 502 $parameters = array();503 $parameters["id"] = $this->id;504 $parameters["mode"] = "add";505 $parameters["field"] = $fName;506 $parameters["value"] = $this->regValues[ $fName ];507 $parameters["pageObj"] = $this;508 $parameters["suggest"] = ($fName == Security::passwordField() || $fName == $this->usernameFiled || $fName == $this->emailFiled);509 510 if( $this->pSet->getEditFormat($fName) == 'Time' )511 $this->fillTimePickSettings( $fName, @$this->regValues[ $fName ] );512 513 if( $fName == Security::passwordField() )514 {515 $parameters["extraParams"] = array();516 $parameters["extraParams"]["getConrirmFieldCtrl"] = true;517 $this->jsSettings['tableSettings'][ $this->tName ]['passFieldName'] = $fName;518 }519 520 if( $fName == $this->usernameFiled )521 $this->jsSettings['tableSettings'][ $this->tName ]['userFieldName'] = $fName;522 523 if( $fName == $this->emailFiled )524 $this->jsSettings['tableSettings'][ $this->tName ]['emailFieldName'] = $fName;525 526 // Add validation527 if( $fName == $this->usernameFiled || $fName == Security::passwordField() || $fName == $this->emailFiled )528 $parameters["validate"] = Array('basicValidate' => Array ( 'IsRequired' ));529 else530 $parameters["validate"] = $this->pSet->getValidation( $fName );531 532 $controls = array('controls' => array());533 $controls["controls"]["id"] = $this->id;534 $controls["controls"]["mode"] = "add";535 $controls["controls"]["ctrlInd"] = 0;536 $controls["controls"]['suggest'] = $parameters["suggest"];537 $controls["controls"]['fieldName'] = $fName;538 539 $this->xt->assign($gfName."_fieldblock", true);540 $this->xt->assign($gfName."_tabfieldblock", true);541 542 $firstElementId = $this->getControl($fName, $this->id)->getFirstElementId();543 if ( $firstElementId )544 $this->xt->assign("labelfor_" . goodFieldName($fName), $firstElementId);545 546 $this->xt->assign_function($gfName."_editcontrol", "xt_buildeditcontrol", $parameters );547 548 $preload = $this->fillPreload($fName, $regFields, $this->regValues);549 if( $preload !== false)550 $controls["controls"]['preloadData'] = $preload;551 552 $this->fillControlsMap( $controls );553 $this->fillControlFlags( $fName, $fName == $this->usernameFiled || $fName == Security::passwordField() || $fName == $this->emailFiled );554 555 // Confirm field for re-enter password556 if( $fName == Security::passwordField() && Security::passwordField() != $this->usernameFiled)557 {558 $parameters = array();559 $parameters["id"] = $this->id;560 $parameters["mode"] = "add";561 $parameters["field"] = "confirm";562 $parameters["format"] = "Password";563 $parameters["suggest"] = true;564 $parameters["pageObj"] = $this;565 $parameters["validate"] = array( 'basicValidate' => array('IsRequired'));566 567 $parameters["extraParams"] = array();568 $parameters["extraParams"]["isConfirm"] = true;569 $parameters["extraParams"]["getConrirmFieldCtrl"] = true;570 571 $controls = array('controls' => array());572 $controls["controls"]['id'] = $this->id;573 $controls["controls"]['mode'] = "add";574 $controls["controls"]['ctrlInd'] = 0;575 $controls["controls"]['suggest'] = true;576 $controls["controls"]['fieldName'] = "confirm";577 578 $this->xt->assign("confirm_label", true);579 if( $this->is508 )580 $this->xt->assign_section("confirm_label", "<label for=\"value_confirm_".$this->id."\">", "</label>");581 582 $this->xt->assign("labelfor_" . goodFieldName($fName) . "_confirm", "value_confirm_".$this->id);583 584 $this->xt->assign_function("confirm_editcontrol1", "xt_buildeditcontrol", $parameters );585 $this->xt->assign("confirm_block", true);586 $this->xt->assign("confirm_fieldblock", true);587 588 $this->fillControlsMap( $controls );589 $this->fillControlFlags( "confirm", true );590 }591 }592 }593 594 /**595 *596 */597 protected function prepareReadonlyFields()598 {599 // show readonly fields600 foreach( $this->pSet->getPageFields() as $uf )601 {602 if( $this->pSet->getEditFormat( $uf ) == EDIT_FORMAT_READONLY )603 $this->readOnlyFields[ $uf ] = $this->showDBValue( $uf , $this->regValues );604 }605 }606 607 /**608 * Get captcha field name609 *610 * @intellisense611 */612 function getCaptchaFieldName()613 {614 return "_register_captcha";615 }616 617 function getCaptchaId()618 {619 return "register";620 }621 622 /**623 *624 */625 public function setDatabaseError( $messageText )626 {627 //global $strMessage;628 $this->message = $messageText;629 }630 631 /**632 *633 */634 protected function doCommonAssignments()635 {636 $this->xt->assign("legend", true);637 638 $this->xt->assign("buttons_block", true);639 640 $this->xt->assign("message_block", true);641 if ( strlen($this->message) ) {642 $messageClass = "alert-danger";643 if ( $this->registerSuccess )644 {645 $messageClass = "alert-success";646 }647 648 $this->xt->assign("message_class", $messageClass );649 $this->xt->assign("message", $this->message);650 } else {651 $this->hideElement("message");652 }653 654 $addStyle = "";655 if ( $this->isMultistepped() )656 $addStyle = " style=\"display: none;\"";657 658 $this->xt->assign("submit_attrs", "id=\"saveButton".$this->id."\"" . $addStyle);659 660 if( GetGlobalData("userRequireActivation") && $this->registerSuccess )661 {662 $this->xt->assign( "firstAboveGridCell", true );663 664 $this->xt->assign("email", $this->strEmail);665 $this->xt->assign("activation_block", true);666 667 $this->xt->assign("activate_message_class",668 $this->sendActivationLinkFailedMessage ? "alert-danger" : "alert-success" );669 670 foreach ( $this->pSet->activatonMessages() as $itemId => $mLString )671 {672 if( $this->sendActivationLinkFailedMessage )673 $label = 'Error sending email.' . $this->sendActivationLinkFailedMessage;674 else675 $label = str_replace( "%email%", runner_htmlspecialchars( $this->strEmail ), GetMLString($mLString) );676 677 $this->xt->assign("label_".$itemId, $label );678 }679 }680 if( $this->registerSuccess )681 {682 $this->xt->assign("registered_block", true);683 $continueUrl = GetTableLink("menu");684 if( Security::userSessionLevel() === LOGGED_2FSETUP_PENDING ) {685 $continueUrl = GetTableLink("userinfo");686 }687 $this->xt->assign("loginlink_attrs",'href="'. $continueUrl .'" id="ProceedToLogin"');688 if( $this->mode == REGISTER_POPUP )689 {690 $this->xt->assign("close_win_btn", true);691 $this->xt->assign("closewindow_attrs", 'id="closeWindowRegister"');692 }693 }694 695 if( $this->mode == REGISTER_POPUP )696 $this->xt->assign("backlink_attrs", 'style="display:none"');697 if( $this->mode == REGISTER_SIMPLE )698 $this->assignBody();699 }700 701 /**702 *703 */704 protected function assignBody()705 {706 if( $this->registerSuccess && !GetGlobalData("userRequireActivation") )707 {708 $this->body["begin"].= GetBaseScriptsForPage( false )709 ."<form method=\"POST\" action=\"".GetTableLink("login")."\" name=\"loginform\">710 <input type=\"Hidden\" name=username value=\"".runner_htmlspecialchars($this->strUsername)."\">".711 "</form>";712 713 714 $this->body['end'] = XTempl::create_method_assignment("assignBodyEnd", $this);715 $this->xt->assign("body", $this->body);716 return;717 }718 719 parent::assignBody();720 }721 722 /**723 *724 */725 protected function showPage()726 {727 global $globalEvents;728 729 if( $this->registerSuccess )730 {731 $this->switchToSuccessPage();732 $this->bodyForms = array( "above-grid", "grid" );733 if( GetGlobalData("userRequireActivation") ) {734 // this must happen after switchToSuccessPage call735 $this->hideItemType("register_proceed");736 $this->hideItemType("register_activated_message");737 }738 }739 740 if( $globalEvents->exists("BeforeShowRegister") )741 $globalEvents->BeforeShowRegister($this->xt, $this->templatefile, $this);742 743 if ( $this->mode == REGISTER_POPUP )744 {745 $this->xt->assign("footer", false);746 $this->xt->assign("header", false);747 $this->xt->assign("body", $this->body); //? true fore register success ?748 749 $this->displayAJAX($this->templatefile, $this->id + 1);750 exit();751 }752 753 $this->display( $this->templatefile );754 return;755 }756 757 /**758 * @return Number759 */760 public static function readRegisterModeFromRequest()761 {762 if( postvalue("onFly") == 1 ) //fix it763 return REGISTER_POPUP;764 765 return REGISTER_SIMPLE;766 }767 768 /**769 * @return String770 */771 public static function readActionFromRequest()772 {773 if( @$_POST["btnSubmit"] )774 return @$_POST["btnSubmit"];775 776 return postvalue("a");777 }778 779 function element2Item( $name ) {780 if( $name == "message" ) {781 return array( "register_message" );782 }783 return parent::element2Item( $name );784 }785 786 787 /**788 * Check if some values are duplicated for the fields not allowing duplicates789 * @param Array ( fieldName => fieldValue , ... )790 * @return Boolean791 */792 public function checkDeniedDuplicated( $values ) {793 $usermessage = "";794 $ret = $this->hasDeniedDuplicateValues( $values, $usermessage );795 if( $ret )796 $this->message = $usermessage;797 798 return !$ret;799 }800 /**801 * Try to login the new user.802 * Create full or provisional session if possible803 */804 protected function tryLoginNewUser() {805 if( !$this->registerSuccess ) {806 return false;807 }808 $userData = Security::fetchUserData( $this->strUsername, "", true );809 if( !$userData ) {810 return false;811 }812 813 // always use username from DB to avoid upper/lower case issues814 $username = $userData[ Security::usernameField() ];815 816 if( GetGlobalData("userRequireActivation") && $userData[ GetGlobalData( "userActivationField" ) ] != 1 ) {817 // create 'activation' provisional session818 Security::createProvisionalSession( Security::dbProvider(), LOGGED_ACTIVATION_PENDING, $username, $userData[ Security::fullnameField() ], $userData );819 } else {820 // create 2fsetup provisional session or a full one821 $twoSettings =& Security::twoFactorSettings();822 if( $twoSettings["enable"] || $twoSettings["required"] ) {823 Security::createProvisionalSession( Security::dbProvider(), LOGGED_2FSETUP_PENDING, $username, $userData[ Security::fullnameField() ], $userData );824 } else {825 Security::createUserSession( Security::dbProvider(), $username, $userData[ Security::fullnameField() ], $userData );826 Security::auditLoginSuccess();827 Security::callAfterLogin();828 }829 }830 return true;831 }832}833?>