Index: branches/5.2.x/core/units/users/users_event_handler.php =================================================================== diff -u -N -r14446 -r14447 --- branches/5.2.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 14446) +++ branches/5.2.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 14447) @@ -1,6 +1,6 @@ isSubscriberOnly($event) ) { $object =& $event->getObject( Array('skip_autoload' => true) ); - /* @var $object kDBItem */ + /* @var $object UsersItem */ if ( $this->Application->ConfigValue('User_Password_Auto') ) { - $pass = kUtil::generatePassword( rand(5, 8) ); - $object->SetField('Password', $pass); - $object->SetField('VerifyPassword', $pass); - $this->Application->SetVar('user_password', $pass); + $password = $object->generatePassword( rand(5, 8) ); + $this->Application->SetVar('user_password', $password); } parent::OnCreate($event); @@ -501,15 +499,14 @@ $cs_helper->PopulateStates($event, 'State', 'Country'); $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object UsersItem */ if ( $this->Application->ConfigValue('Email_As_Login') ) { $field_options = $object->GetFieldOptions('Email'); $field_options['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist'); $object->SetFieldOptions('Email', $field_options); } - $object->setLogin(); $this->setUserGroup($object); $user_helper =& $this->Application->recallObject('UserHelper'); @@ -738,9 +735,8 @@ } } else { - $password = makepassword4(); - $object->SetField('Password', $password); - $object->SetField('VerifyPassword', $password); + $object->generatePassword(); + $object->SetDBField('Email', $user_email); $object->SetDBField('Login', $user_email); $object->SetDBField('Status', STATUS_ACTIVE); // make user subscriber Active by default @@ -936,13 +932,9 @@ $user_object->SetDBField('PwRequestTime', 0); if ($exp_time > adodb_mktime()) { - $newpw = kUtil::generatePassword(); - + $newpw = $user_object->generatePassword(); $this->Application->StoreVar('password', $newpw); - $user_object->SetField('Password', $newpw); - $user_object->SetField('VerifyPassword', $newpw); - $user_object->SetDBField('PassResetTime', adodb_mktime()); $user_object->SetDBField('PwResetConfirm', ''); $user_object->SetDBField('PwRequestTime', 0); @@ -990,11 +982,6 @@ $cs_helper->CheckStateField($event, 'State', 'Country'); $cs_helper->PopulateStates($event, 'State', 'Country'); - - $object =& $event->getObject(); - /* @var $object UsersItem */ - - $object->setLogin(); } /** @@ -1405,6 +1392,8 @@ { parent::OnAfterConfigRead($event); + $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); + // 1. arrange user registration countries $site_helper =& $this->Application->recallObject('SiteHelper'); /* @var $site_helper SiteHelper */ @@ -1415,7 +1404,6 @@ $first_country = $this->Application->ConfigValue('User_Default_Registration_Country'); } - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); if ($first_country) { // update user country dropdown sql @@ -1424,7 +1412,6 @@ // 2. set default user registration group $fields['PrimaryGroupId']['default'] = $this->Application->ConfigValue('User_NewGroup'); - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); // 3. allow avatar upload on Front-End $file_helper =& $this->Application->recallObject('FileHelper'); @@ -1434,10 +1421,7 @@ if ($this->Application->isAdminUser) { // 4. when in administrative console, then create all users with Active status - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); -// $fields['Password']['required'] = 1; // set password required (will broke approve/decline buttons) $fields['Status']['default'] = STATUS_ACTIVE; - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); // 5. remove groups tab on editing forms when AdvancedUserManagement config variable not set if (!$this->Application->ConfigValue('AdvancedUserManagement')) { @@ -1457,6 +1441,13 @@ $this->Application->setUnitOption($event->Prefix, 'EditTabPresets', $edit_tab_presets); } } + + if ( !$this->Application->ConfigValue('Email_As_Login') ) { + // Login becomes required only, when it's used in registration process + $fields['Login']['required'] = 1; + } + + $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); } /** @@ -1487,12 +1478,9 @@ function OnBeforeClone(&$event) { $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object UsersItem */ - $password = kUtil::generatePassword(); - $object->SetField('Password', $password); - $object->SetField('VerifyPassword', $password); - + $object->generatePassword(); $object->SetDBField('ResourceId', 0); // this will reset it // change email because it should be unique