Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/users/users_event_handler.php
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnItemBuild(kEvent $event) | protected function OnItemBuild(kEvent $event) | ||||
{ | { | ||||
parent::OnItemBuild($event); | parent::OnItemBuild($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $event->Special == 'forgot' || $object->getFormName() == 'registration' ) { | if ( $event->Special == 'forgot' || $object->getFormName() == 'registration' ) { | ||||
$this->_makePasswordRequired($event); | $this->_makePasswordRequired($event); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Shows only admins when required | * Shows only admins when required | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
* @see kDBEventHandler::OnListBuild() | * @see kDBEventHandler::OnListBuild() | ||||
*/ | */ | ||||
protected function SetCustomQuery(kEvent $event) | protected function SetCustomQuery(kEvent $event) | ||||
{ | { | ||||
parent::SetCustomQuery($event); | parent::SetCustomQuery($event); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
if ( $event->Special == 'regular' ) { | if ( $event->Special == 'regular' ) { | ||||
$object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::USER); | $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::USER); | ||||
} | } | ||||
if ( $event->Special == 'admins' ) { | if ( $event->Special == 'admins' ) { | ||||
$object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::ADMIN); | $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::ADMIN); | ||||
} | } | ||||
Show All 37 Lines | |||||
return true; | return true; | ||||
} | } | ||||
if ( $event->Name == 'OnResetRootPassword' ) { | if ( $event->Name == 'OnResetRootPassword' ) { | ||||
return defined('DBG_RESET_ROOT') && DBG_RESET_ROOT; | return defined('DBG_RESET_ROOT') && DBG_RESET_ROOT; | ||||
} | } | ||||
if ( $event->Name == 'OnLoginAs' ) { | if ( $event->Name == 'OnLoginAs' ) { | ||||
/** @var Session $admin_session */ | |||||
$admin_session = $this->Application->recallObject('Session.admin'); | $admin_session = $this->Application->recallObject('Session.admin'); | ||||
/* @var $admin_session Session */ | |||||
return $admin_session->LoggedIn(); | return $admin_session->LoggedIn(); | ||||
} | } | ||||
if ( !$this->Application->isAdminUser ) { | if ( !$this->Application->isAdminUser ) { | ||||
$user_id = $this->Application->RecallVar('user_id'); | $user_id = $this->Application->RecallVar('user_id'); | ||||
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); | $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); | ||||
if ( ($event->Name == 'OnCreate' || $event->Name == 'OnRegisterAjax') && $user_id == USER_GUEST ) { | if ( ($event->Name == 'OnCreate' || $event->Name == 'OnRegisterAjax') && $user_id == USER_GUEST ) { | ||||
// "Guest" can create new users | // "Guest" can create new users | ||||
return true; | return true; | ||||
} | } | ||||
if ( substr($event->Name, 0, 8) == 'OnUpdate' && $user_id > 0 ) { | if ( substr($event->Name, 0, 8) == 'OnUpdate' && $user_id > 0 ) { | ||||
/** @var UsersItem $user_dummy */ | |||||
$user_dummy = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true)); | $user_dummy = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true)); | ||||
/* @var $user_dummy UsersItem */ | |||||
foreach ($items_info as $id => $field_values) { | foreach ($items_info as $id => $field_values) { | ||||
if ( $id != $user_id ) { | if ( $id != $user_id ) { | ||||
// registered users can update their record only | // registered users can update their record only | ||||
return false; | return false; | ||||
} | } | ||||
$user_dummy->Load($id); | $user_dummy->Load($id); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
); | ); | ||||
if ($this->Application->isAdmin) { | if ($this->Application->isAdmin) { | ||||
$this->Application->Redirect('index', $admin_url_params, '', 'index.php'); | $this->Application->Redirect('index', $admin_url_params, '', 'index.php'); | ||||
} | } | ||||
if ($this->Application->GetVar('admin') == 1) { | if ($this->Application->GetVar('admin') == 1) { | ||||
// Front-End showed in admin's right frame | // Front-End showed in admin's right frame | ||||
/** @var Session $session_admin */ | |||||
$session_admin = $this->Application->recallObject('Session.admin'); | $session_admin = $this->Application->recallObject('Session.admin'); | ||||
/* @var $session_admin Session */ | |||||
if (!$session_admin->LoggedIn()) { | if (!$session_admin->LoggedIn()) { | ||||
// front-end session created from admin session & both expired | // front-end session created from admin session & both expired | ||||
$this->Application->DeleteVar('admin'); | $this->Application->DeleteVar('admin'); | ||||
$this->Application->Redirect('index', $admin_url_params, '', 'admin/index.php'); | $this->Application->Redirect('index', $admin_url_params, '', 'admin/index.php'); | ||||
} | } | ||||
} | } | ||||
Show All 24 Lines | |||||
* Checks user data and logs it in if allowed | * Checks user data and logs it in if allowed | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnLogin($event) | protected function OnLogin($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject( Array ('form_name' => 'login') ); | $object = $event->getObject( Array ('form_name' => 'login') ); | ||||
/* @var $object kDBItem */ | |||||
$object->SetFieldsFromHash($this->getSubmittedFields($event)); | $object->SetFieldsFromHash($this->getSubmittedFields($event)); | ||||
$username = $object->GetDBField('UserLogin'); | $username = $object->GetDBField('UserLogin'); | ||||
$password = $object->GetDBField('UserPassword'); | $password = $object->GetDBField('UserPassword'); | ||||
$remember_login = $object->GetDBField('UserRememberLogin') == 1; | $remember_login = $object->GetDBField('UserRememberLogin') == 1; | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$user_helper->event =& $event; | $user_helper->event =& $event; | ||||
$result = $user_helper->loginUser($username, $password, false, $remember_login); | $result = $user_helper->loginUser($username, $password, false, $remember_login); | ||||
if ($result != LoginResult::OK) { | if ($result != LoginResult::OK) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
$object->SetError('UserLogin', $result == LoginResult::NO_PERMISSION ? 'no_permission' : 'invalid_password'); | $object->SetError('UserLogin', $result == LoginResult::NO_PERMISSION ? 'no_permission' : 'invalid_password'); | ||||
Show All 10 Lines | |||||
* Performs user login from ajax request | * Performs user login from ajax request | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnLoginAjax($event) | protected function OnLoginAjax($event) | ||||
{ | { | ||||
/** @var AjaxFormHelper $ajax_form_helper */ | |||||
$ajax_form_helper = $this->Application->recallObject('AjaxFormHelper'); | $ajax_form_helper = $this->Application->recallObject('AjaxFormHelper'); | ||||
/* @var $ajax_form_helper AjaxFormHelper */ | |||||
$ajax_form_helper->transitEvent($event, 'OnLogin'); | $ajax_form_helper->transitEvent($event, 'OnLogin'); | ||||
} | } | ||||
/** | /** | ||||
* [HOOK] Auto-Logins Front-End user when "Remember Login" cookie is found | * [HOOK] Auto-Logins Front-End user when "Remember Login" cookie is found | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnAutoLoginUser($event) | function OnAutoLoginUser($event) | ||||
{ | { | ||||
$remember_login_cookie = $this->Application->GetVar('remember_login'); | $remember_login_cookie = $this->Application->GetVar('remember_login'); | ||||
if (!$remember_login_cookie || $this->Application->isAdmin || $this->Application->LoggedIn()) { | if (!$remember_login_cookie || $this->Application->isAdmin || $this->Application->LoggedIn()) { | ||||
return ; | return ; | ||||
} | } | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$user_helper->loginUser('', '', false, false, $remember_login_cookie); | $user_helper->loginUser('', '', false, false, $remember_login_cookie); | ||||
} | } | ||||
/** | /** | ||||
* Called when user logs in using old in-portal | * Called when user logs in using old in-portal | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnInpLogin($event) | function OnInpLogin($event) | ||||
{ | { | ||||
/** @var UsersSyncronizeManager $sync_manager */ | |||||
$sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); | $sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); | ||||
/* @var $sync_manager UsersSyncronizeManager */ | |||||
$sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') ); | $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') ); | ||||
if ($event->redirect && is_string($event->redirect)) { | if ($event->redirect && is_string($event->redirect)) { | ||||
// some real template specified instead of true | // some real template specified instead of true | ||||
$this->Application->Redirect($event->redirect, $event->getRedirectParams()); | $this->Application->Redirect($event->redirect, $event->getRedirectParams()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Called when user logs in using old in-portal | * Called when user logs in using old in-portal | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnInpLogout($event) | function OnInpLogout($event) | ||||
{ | { | ||||
/** @var UsersSyncronizeManager $sync_manager */ | |||||
$sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); | $sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); | ||||
/* @var $sync_manager UsersSyncronizeManager */ | |||||
$sync_manager->performAction('LogoutUser'); | $sync_manager->performAction('LogoutUser'); | ||||
} | } | ||||
/** | /** | ||||
* Performs user logout | * Performs user logout | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnLogout($event) | protected function OnLogout($event) | ||||
{ | { | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$user_helper->event =& $event; | $user_helper->event =& $event; | ||||
$user_helper->logoutUser(); | $user_helper->logoutUser(); | ||||
} | } | ||||
/** | /** | ||||
* Redirects user after successful registration to confirmation template (on Front only) | * Redirects user after successful registration to confirmation template (on Front only) | ||||
Show All 21 Lines | |||||
protected function OnCreate(kEvent $event) | protected function OnCreate(kEvent $event) | ||||
{ | { | ||||
if ( $this->Application->isAdmin ) { | if ( $this->Application->isAdmin ) { | ||||
parent::OnCreate($event); | parent::OnCreate($event); | ||||
return ; | return ; | ||||
} | } | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject( Array('form_name' => 'registration') ); | $object = $event->getObject( Array('form_name' => 'registration') ); | ||||
/* @var $object UsersItem */ | |||||
$field_values = $this->getSubmittedFields($event); | $field_values = $this->getSubmittedFields($event); | ||||
$user_email = getArrayValue($field_values, 'Email'); | $user_email = getArrayValue($field_values, 'Email'); | ||||
$subscriber_id = $user_email ? $this->getSubscriberByEmail($user_email) : false; | $subscriber_id = $user_email ? $this->getSubscriberByEmail($user_email) : false; | ||||
if ( $subscriber_id ) { | if ( $subscriber_id ) { | ||||
// update existing subscriber | // update existing subscriber | ||||
$object->Load($subscriber_id); | $object->Load($subscriber_id); | ||||
Show All 26 Lines | |||||
* Processes user registration from ajax request | * Processes user registration from ajax request | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnRegisterAjax(kEvent $event) | protected function OnRegisterAjax(kEvent $event) | ||||
{ | { | ||||
/** @var AjaxFormHelper $ajax_form_helper */ | |||||
$ajax_form_helper = $this->Application->recallObject('AjaxFormHelper'); | $ajax_form_helper = $this->Application->recallObject('AjaxFormHelper'); | ||||
/* @var $ajax_form_helper AjaxFormHelper */ | |||||
$ajax_form_helper->transitEvent($event, 'OnCreate', Array ('do_refresh' => 1)); | $ajax_form_helper->transitEvent($event, 'OnCreate', Array ('do_refresh' => 1)); | ||||
} | } | ||||
/** | /** | ||||
* Returns subscribed user ID by given e-mail address | * Returns subscribed user ID by given e-mail address | ||||
* | * | ||||
* @param string $email | * @param string $email | ||||
* @return int|bool | * @return int|bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function getSubscriberByEmail($email) | protected function getSubscriberByEmail($email) | ||||
{ | { | ||||
/** @var UsersItem $verify_user */ | |||||
$verify_user = $this->Application->recallObject('u.verify', null, Array ('skip_autoload' => true)); | $verify_user = $this->Application->recallObject('u.verify', null, Array ('skip_autoload' => true)); | ||||
/* @var $verify_user UsersItem */ | |||||
$verify_user->Load($email, 'Email'); | $verify_user->Load($email, 'Email'); | ||||
return $verify_user->isLoaded() && $verify_user->isSubscriberOnly() ? $verify_user->GetID() : false; | return $verify_user->isLoaded() && $verify_user->isSubscriberOnly() ? $verify_user->GetID() : false; | ||||
} | } | ||||
/** | /** | ||||
* Login user if possible, if not then redirect to corresponding template | * Login user if possible, if not then redirect to corresponding template | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function autoLoginUser($event) | function autoLoginUser($event) | ||||
{ | { | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
if ( $object->GetDBField('Status') == STATUS_ACTIVE ) { | if ( $object->GetDBField('Status') == STATUS_ACTIVE ) { | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$user =& $user_helper->getUserObject(); | $user =& $user_helper->getUserObject(); | ||||
$user->Load($object->GetID()); | $user->Load($object->GetID()); | ||||
if ( $user_helper->checkLoginPermission() ) { | if ( $user_helper->checkLoginPermission() ) { | ||||
$user_helper->loginUserById( $user->GetID() ); | $user_helper->loginUserById( $user->GetID() ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Set's new unique resource id to user | * Set's new unique resource id to user | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemCreate(kEvent $event) | protected function OnBeforeItemCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemCreate($event); | parent::OnBeforeItemCreate($event); | ||||
$this->beforeItemChanged($event); | $this->beforeItemChanged($event); | ||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
if ( !$object->isSubscriberOnly() ) { | if ( !$object->isSubscriberOnly() ) { | ||||
// don't check state-to-country relations for subscribers | // don't check state-to-country relations for subscribers | ||||
$cs_helper->CheckStateField($event, 'State', 'Country'); | $cs_helper->CheckStateField($event, 'State', 'Country'); | ||||
} | } | ||||
if ( $object->getFormName() != 'login' ) { | if ( $object->getFormName() != 'login' ) { | ||||
$this->_makePasswordRequired($event); | $this->_makePasswordRequired($event); | ||||
} | } | ||||
$cs_helper->PopulateStates($event, 'State', 'Country'); | $cs_helper->PopulateStates($event, 'State', 'Country'); | ||||
$this->setUserGroup($object); | $this->setUserGroup($object); | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
if ( !$user_helper->checkBanRules($object) ) { | if ( !$user_helper->checkBanRules($object) ) { | ||||
$object->SetError('Username', 'banned'); | $object->SetError('Username', 'banned'); | ||||
} | } | ||||
$object->SetDBField('IPAddress', $this->Application->getClientIp()); | $object->SetDBField('IPAddress', $this->Application->getClientIp()); | ||||
Show All 36 Lines | |||||
/** | /** | ||||
* Assigns a user to it's primary group | * Assigns a user to it's primary group | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
protected function assignToPrimaryGroup($event) | protected function assignToPrimaryGroup($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$primary_group_id = $object->GetDBField('PrimaryGroupId'); | $primary_group_id = $object->GetDBField('PrimaryGroupId'); | ||||
if ($primary_group_id) { | if ($primary_group_id) { | ||||
$ug_table = TABLE_PREFIX . 'UserGroupRelations'; | $ug_table = TABLE_PREFIX . 'UserGroupRelations'; | ||||
if ( $object->IsTempTable() ) { | if ( $object->IsTempTable() ) { | ||||
$ug_table = $this->Application->GetTempName($ug_table, 'prefix:' . $event->Prefix); | $ug_table = $this->Application->GetTempName($ug_table, 'prefix:' . $event->Prefix); | ||||
Show All 12 Lines | |||||
* Set's new unique resource id to user | * Set's new unique resource id to user | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemValidate(kEvent $event) | protected function OnAfterItemValidate(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$resource_id = $object->GetDBField('ResourceId'); | $resource_id = $object->GetDBField('ResourceId'); | ||||
if ( !$resource_id ) { | if ( !$resource_id ) { | ||||
$object->SetDBField('ResourceId', $this->Application->NextResourceId()); | $object->SetDBField('ResourceId', $this->Application->NextResourceId()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Enter description here... | * Enter description here... | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnRecommend($event) | function OnRecommend($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject( Array ('form_name' => 'recommend') ); | $object = $event->getObject( Array ('form_name' => 'recommend') ); | ||||
/* @var $object kDBItem */ | |||||
$object->SetFieldsFromHash($this->getSubmittedFields($event)); | $object->SetFieldsFromHash($this->getSubmittedFields($event)); | ||||
if ( !$object->ValidateField('RecommendEmail') ) { | if ( !$object->ValidateField('RecommendEmail') ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
return ; | return ; | ||||
} | } | ||||
Show All 19 Lines | |||||
/** | /** | ||||
* Saves address changes and mades no redirect | * Saves address changes and mades no redirect | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnUpdateAddress($event) | function OnUpdateAddress($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(Array ('skip_autoload' => true)); | $object = $event->getObject(Array ('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | |||||
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); | $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); | ||||
if ( $items_info ) { | if ( $items_info ) { | ||||
list ($id, $field_values) = each($items_info); | list ($id, $field_values) = each($items_info); | ||||
if ( $id > 0 ) { | if ( $id > 0 ) { | ||||
$object->Load($id); | $object->Load($id); | ||||
} | } | ||||
$object->setID($id); | $object->setID($id); | ||||
$object->SetFieldsFromHash($field_values); | $object->SetFieldsFromHash($field_values); | ||||
$event->setEventParam('form_data', $field_values); | $event->setEventParam('form_data', $field_values); | ||||
$object->Validate(); | $object->Validate(); | ||||
} | } | ||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
$cs_helper->PopulateStates($event, 'State', 'Country'); | $cs_helper->PopulateStates($event, 'State', 'Country'); | ||||
$event->redirect = false; | $event->redirect = false; | ||||
} | } | ||||
/** | /** | ||||
* Validate subscriber's email & store it to session -> redirect to confirmation template | * Validate subscriber's email & store it to session -> redirect to confirmation template | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSubscribeQuery($event) | function OnSubscribeQuery($event) | ||||
{ | { | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject( Array ('form_name' => 'subscription') ); | $object = $event->getObject( Array ('form_name' => 'subscription') ); | ||||
/* @var $object UsersItem */ | |||||
$object->SetFieldsFromHash($this->getSubmittedFields($event)); | $object->SetFieldsFromHash($this->getSubmittedFields($event)); | ||||
if ( !$object->ValidateField('SubscriberEmail') ) { | if ( !$object->ValidateField('SubscriberEmail') ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
return ; | return ; | ||||
} | } | ||||
Show All 14 Lines | |||||
/** | /** | ||||
* Subscribe/Unsubscribe user based on email stored in previous step | * Subscribe/Unsubscribe user based on email stored in previous step | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSubscribeUser($event) | function OnSubscribeUser($event) | ||||
{ | { | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject( Array ('form_name' => 'subscription') ); | $object = $event->getObject( Array ('form_name' => 'subscription') ); | ||||
/* @var $object UsersItem */ | |||||
$user_email = $this->Application->GetVar('subscriber_email'); | $user_email = $this->Application->GetVar('subscriber_email'); | ||||
$object->SetDBField('SubscriberEmail', $user_email); | $object->SetDBField('SubscriberEmail', $user_email); | ||||
if ( !$object->ValidateField('SubscriberEmail') ) { | if ( !$object->ValidateField('SubscriberEmail') ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
return ; | return ; | ||||
} | } | ||||
$username_required = $object->isRequired('Username'); | $username_required = $object->isRequired('Username'); | ||||
$this->RemoveRequiredFields($object); | $this->RemoveRequiredFields($object); | ||||
$object->Load($user_email, 'Email'); | $object->Load($user_email, 'Email'); | ||||
if ( $object->isLoaded() ) { | if ( $object->isLoaded() ) { | ||||
if ( $object->isSubscribed() ) { | if ( $object->isSubscribed() ) { | ||||
if ( $event->getEventParam('no_unsubscribe') ) { | if ( $event->getEventParam('no_unsubscribe') ) { | ||||
// for customization code from FormsEventHandler | // for customization code from FormsEventHandler | ||||
return ; | return ; | ||||
} | } | ||||
if ( $object->isSubscriberOnly() ) { | if ( $object->isSubscriberOnly() ) { | ||||
/** @var kTempTablesHandler $temp_handler */ | |||||
$temp_handler = $this->Application->recallObject($event->Prefix . '_TempHandler', 'kTempTablesHandler'); | $temp_handler = $this->Application->recallObject($event->Prefix . '_TempHandler', 'kTempTablesHandler'); | ||||
/* @var $temp_handler kTempTablesHandler */ | |||||
$temp_handler->DeleteItems($event->Prefix, '', Array($object->GetID())); | $temp_handler->DeleteItems($event->Prefix, '', Array($object->GetID())); | ||||
} | } | ||||
else { | else { | ||||
$this->RemoveSubscriberGroup( $object->GetID() ); | $this->RemoveSubscriberGroup( $object->GetID() ); | ||||
} | } | ||||
$event->redirect = $this->Application->GetVar('unsubscribe_ok_template'); | $event->redirect = $this->Application->GetVar('unsubscribe_ok_template'); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Validates forgot password form and sends password reset confirmation e-mail | * Validates forgot password form and sends password reset confirmation e-mail | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
function OnForgotPassword($event) | function OnForgotPassword($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject( Array ('form_name' => 'forgot_password') ); | $object = $event->getObject( Array ('form_name' => 'forgot_password') ); | ||||
/* @var $object kDBItem */ | |||||
$object->SetFieldsFromHash($this->getSubmittedFields($event)); | $object->SetFieldsFromHash($this->getSubmittedFields($event)); | ||||
/** @var UsersItem $user */ | |||||
$user = $this->Application->recallObject('u.tmp', null, Array ('skip_autoload' => true)); | $user = $this->Application->recallObject('u.tmp', null, Array ('skip_autoload' => true)); | ||||
/* @var $user UsersItem */ | |||||
$found = $allow_reset = false; | $found = $allow_reset = false; | ||||
$email_or_username = $object->GetDBField('ForgotLogin'); | $email_or_username = $object->GetDBField('ForgotLogin'); | ||||
$is_email = strpos($email_or_username, '@') !== false; | $is_email = strpos($email_or_username, '@') !== false; | ||||
if ( strlen($email_or_username) ) { | if ( strlen($email_or_username) ) { | ||||
$user->Load($email_or_username, $is_email ? 'Email' : 'Username'); | $user->Load($email_or_username, $is_email ? 'Email' : 'Username'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemUpdate(kEvent $event) | protected function OnBeforeItemUpdate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemUpdate($event); | parent::OnBeforeItemUpdate($event); | ||||
$this->beforeItemChanged($event); | $this->beforeItemChanged($event); | ||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
$cs_helper->CheckStateField($event, 'State', 'Country'); | $cs_helper->CheckStateField($event, 'State', 'Country'); | ||||
$cs_helper->PopulateStates($event, 'State', 'Country'); | $cs_helper->PopulateStates($event, 'State', 'Country'); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $event->Special == 'forgot' ) { | if ( $event->Special == 'forgot' ) { | ||||
$object->SetDBField('PwResetConfirm', ''); | $object->SetDBField('PwResetConfirm', ''); | ||||
$object->SetDBField('PwRequestTime_date', NULL); | $object->SetDBField('PwRequestTime_date', NULL); | ||||
$object->SetDBField('PwRequestTime_time', NULL); | $object->SetDBField('PwRequestTime_time', NULL); | ||||
} | } | ||||
$changed_fields = array_keys($object->GetChangedFields()); | $changed_fields = array_keys($object->GetChangedFields()); | ||||
Show All 10 Lines | |||||
/** | /** | ||||
* Occurs before item is changed | * Occurs before item is changed | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function beforeItemChanged($event) | function beforeItemChanged($event) | ||||
{ | { | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
if ( !$this->Application->isAdmin && $object->getFormName() == 'registration' ) { | if ( !$this->Application->isAdmin && $object->getFormName() == 'registration' ) { | ||||
// sets new user's status based on config options | // sets new user's status based on config options | ||||
$status_map = Array (1 => STATUS_ACTIVE, 2 => STATUS_DISABLED, 3 => STATUS_PENDING, 4 => STATUS_PENDING); | $status_map = Array (1 => STATUS_ACTIVE, 2 => STATUS_DISABLED, 3 => STATUS_PENDING, 4 => STATUS_PENDING); | ||||
$object->SetDBField('Status', $status_map[ $this->Application->ConfigValue('User_Allow_New') ]); | $object->SetDBField('Status', $status_map[ $this->Application->ConfigValue('User_Allow_New') ]); | ||||
if ( $this->Application->ConfigValue('User_Password_Auto') ) { | if ( $this->Application->ConfigValue('User_Password_Auto') ) { | ||||
$object->generatePassword( rand(5, 8) ); | $object->generatePassword( rand(5, 8) ); | ||||
} | } | ||||
if ( $this->Application->ConfigValue('RegistrationCaptcha') ) { | if ( $this->Application->ConfigValue('RegistrationCaptcha') ) { | ||||
/** @var kCaptchaHelper $captcha_helper */ | |||||
$captcha_helper = $this->Application->recallObject('CaptchaHelper'); | $captcha_helper = $this->Application->recallObject('CaptchaHelper'); | ||||
/* @var $captcha_helper kCaptchaHelper */ | |||||
$captcha_helper->validateCode($event, false); | $captcha_helper->validateCode($event, false); | ||||
} | } | ||||
if ( $event->Name == 'OnBeforeItemUpdate' ) { | if ( $event->Name == 'OnBeforeItemUpdate' ) { | ||||
// when a subscriber-only users performs normal registration, then assign him to Member group | // when a subscriber-only users performs normal registration, then assign him to Member group | ||||
$this->setUserGroup($object); | $this->setUserGroup($object); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Sets redirect template based on user status & user request contents | * Sets redirect template based on user status & user request contents | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @param bool $for_registration | * @param bool $for_registration | ||||
*/ | */ | ||||
function setNextTemplate($event, $for_registration = false) | function setNextTemplate($event, $for_registration = false) | ||||
{ | { | ||||
$event->SetRedirectParam('opener', 's'); | $event->SetRedirectParam('opener', 's'); | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
$next_template = false; | $next_template = false; | ||||
if ( $object->GetDBField('Status') == STATUS_ACTIVE && $this->Application->GetVar('next_template') ) { | if ( $object->GetDBField('Status') == STATUS_ACTIVE && $this->Application->GetVar('next_template') ) { | ||||
$next_template = $this->Application->GetVar('next_template'); | $next_template = $this->Application->GetVar('next_template'); | ||||
} | } | ||||
elseif ( $for_registration ) { | elseif ( $for_registration ) { | ||||
switch ( $this->Application->ConfigValue('User_Allow_New') ) { | switch ( $this->Application->ConfigValue('User_Allow_New') ) { | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnRefreshForm($event) | protected function OnRefreshForm($event) | ||||
{ | { | ||||
$event->redirect = false; | $event->redirect = false; | ||||
$item_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); | $item_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); | ||||
list($id, $field_values) = each($item_info); | list($id, $field_values) = each($item_info); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject( Array ('skip_autoload' => true) ); | $object = $event->getObject( Array ('skip_autoload' => true) ); | ||||
/* @var $object kDBItem */ | |||||
$object->IgnoreValidation = true; | $object->IgnoreValidation = true; | ||||
$object->setID($id); | $object->setID($id); | ||||
$object->SetFieldsFromHash($field_values); | $object->SetFieldsFromHash($field_values); | ||||
$event->setEventParam('form_data', $field_values); | $event->setEventParam('form_data', $field_values); | ||||
} | } | ||||
Show All 20 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return int | * @return int | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function getPassedID(kEvent $event) | public function getPassedID(kEvent $event) | ||||
{ | { | ||||
switch ($event->Special) { | switch ($event->Special) { | ||||
case 'ord': | case 'ord': | ||||
/** @var OrdersItem $order */ | |||||
$order = $this->Application->recallObject('ord'); | $order = $this->Application->recallObject('ord'); | ||||
/* @var $order OrdersItem */ | |||||
return $order->GetDBField('PortalUserId'); | return $order->GetDBField('PortalUserId'); | ||||
break; | break; | ||||
case 'profile': | case 'profile': | ||||
$id = $this->Application->GetVar('user_id'); | $id = $this->Application->GetVar('user_id'); | ||||
if ( $id ) { | if ( $id ) { | ||||
$event->setEventParam(kEvent::FLAG_ID_FROM_REQUEST, true); | $event->setEventParam(kEvent::FLAG_ID_FROM_REQUEST, true); | ||||
return $id; | return $id; | ||||
} | } | ||||
// If none user_id given use current user id. | // If none user_id given use current user id. | ||||
return $this->Application->RecallVar('user_id'); | return $this->Application->RecallVar('user_id'); | ||||
break; | break; | ||||
case 'forgot': | case 'forgot': | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$id = $user_helper->validateUserCode($this->Application->GetVar('user_key'), 'forgot_password'); | $id = $user_helper->validateUserCode($this->Application->GetVar('user_key'), 'forgot_password'); | ||||
if ( is_numeric($id) ) { | if ( is_numeric($id) ) { | ||||
return $id; | return $id; | ||||
} | } | ||||
break; | break; | ||||
Show All 24 Lines | |||||
if ( !$items_info ) { | if ( !$items_info ) { | ||||
return; | return; | ||||
} | } | ||||
list ($id, $field_values) = each($items_info); | list ($id, $field_values) = each($items_info); | ||||
$user_id = $this->Application->RecallVar('user_id'); | $user_id = $this->Application->RecallVar('user_id'); | ||||
if ( $id == $user_id && ($user_id > 0 || $user_id == USER_ROOT) ) { | if ( $id == $user_id && ($user_id > 0 || $user_id == USER_ROOT) ) { | ||||
/** @var kDBItem $user_dummy */ | |||||
$user_dummy = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true)); | $user_dummy = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true)); | ||||
/* @var $user_dummy kDBItem */ | |||||
$user_dummy->Load($id); | $user_dummy->Load($id); | ||||
$status_field = $user_dummy->getStatusField(); | $status_field = $user_dummy->getStatusField(); | ||||
if ( $user_dummy->GetDBField($status_field) != STATUS_ACTIVE ) { | if ( $user_dummy->GetDBField($status_field) != STATUS_ACTIVE ) { | ||||
// not active user is not allowed to update his record (he could not activate himself manually) | // not active user is not allowed to update his record (he could not activate himself manually) | ||||
return ; | return ; | ||||
} | } | ||||
} | } | ||||
if ( $user_id == USER_ROOT ) { | if ( $user_id == USER_ROOT ) { | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(Array ('skip_autoload' => true)); | $object = $event->getObject(Array ('skip_autoload' => true)); | ||||
/* @var $object UsersItem */ | |||||
// this is internal hack to allow root/root passwords for dev | // this is internal hack to allow root/root passwords for dev | ||||
if ( $this->Application->isDebugMode() && $field_values['RootPassword'] == 'root' ) { | if ( $this->Application->isDebugMode() && $field_values['RootPassword'] == 'root' ) { | ||||
$object->SetFieldOption('RootPassword', 'min_length', 4); | $object->SetFieldOption('RootPassword', 'min_length', 4); | ||||
} | } | ||||
$this->RemoveRequiredFields($object); | $this->RemoveRequiredFields($object); | ||||
$object->SetDBField('RootPassword', $this->Application->ConfigValue('RootPass')); | $object->SetDBField('RootPassword', $this->Application->ConfigValue('RootPass')); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
* Checks, that currently loaded item is allowed for viewing (non permission-based) | * Checks, that currently loaded item is allowed for viewing (non permission-based) | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return bool | * @return bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function checkItemStatus(kEvent $event) | protected function checkItemStatus(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( !$object->isLoaded() ) { | if ( !$object->isLoaded() ) { | ||||
return true; | return true; | ||||
} | } | ||||
$virtual_users = Array (USER_ROOT, USER_GUEST); | $virtual_users = Array (USER_ROOT, USER_GUEST); | ||||
return ($object->GetDBField('Status') == STATUS_ACTIVE) || in_array($object->GetID(), $virtual_users); | return ($object->GetDBField('Status') == STATUS_ACTIVE) || in_array($object->GetID(), $virtual_users); | ||||
} | } | ||||
/** | /** | ||||
* Sends approved/declined email event on user status change | * Sends approved/declined email event on user status change | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemUpdate(kEvent $event) | protected function OnAfterItemUpdate(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterItemUpdate($event); | parent::OnAfterItemUpdate($event); | ||||
$this->afterItemChanged($event); | $this->afterItemChanged($event); | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
if ( !$this->Application->isAdmin && ($event->Special != 'email-restore') ) { | if ( !$this->Application->isAdmin && ($event->Special != 'email-restore') ) { | ||||
$this->sendEmailChangeEvent($event); | $this->sendEmailChangeEvent($event); | ||||
} | } | ||||
if ( !$this->Application->isAdmin || $object->IsTempTable() ) { | if ( !$this->Application->isAdmin || $object->IsTempTable() ) { | ||||
return; | return; | ||||
} | } | ||||
$this->sendStatusChangeEvent($object->GetID(), $object->GetOriginalField('Status'), $object->GetDBField('Status')); | $this->sendStatusChangeEvent($object->GetID(), $object->GetOriginalField('Status'), $object->GetDBField('Status')); | ||||
} | } | ||||
/** | /** | ||||
* Occurs, after item is changed | * Occurs, after item is changed | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
protected function afterItemChanged($event) | protected function afterItemChanged($event) | ||||
{ | { | ||||
$this->saveUserImages($event); | $this->saveUserImages($event); | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
if ( $object->GetDBField('EmailPassword') && $object->GetDBField('Password_plain') ) { | if ( $object->GetDBField('EmailPassword') && $object->GetDBField('Password_plain') ) { | ||||
$email_passwords = $this->Application->RecallVar('email_passwords'); | $email_passwords = $this->Application->RecallVar('email_passwords'); | ||||
$email_passwords = $email_passwords ? unserialize($email_passwords) : Array (); | $email_passwords = $email_passwords ? unserialize($email_passwords) : Array (); | ||||
$email_passwords[ $object->GetID() ] = $object->GetDBField('Password_plain'); | $email_passwords[ $object->GetID() ] = $object->GetDBField('Password_plain'); | ||||
$this->Application->StoreVar('email_passwords', serialize($email_passwords)); | $this->Application->StoreVar('email_passwords', serialize($email_passwords)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
$temp_id = $event->getEventParam('temp_id'); | $temp_id = $event->getEventParam('temp_id'); | ||||
$email_passwords = $this->Application->RecallVar('email_passwords'); | $email_passwords = $this->Application->RecallVar('email_passwords'); | ||||
if ( $email_passwords ) { | if ( $email_passwords ) { | ||||
$email_passwords = unserialize($email_passwords); | $email_passwords = unserialize($email_passwords); | ||||
if ( isset($email_passwords[$temp_id]) ) { | if ( isset($email_passwords[$temp_id]) ) { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$object->SwitchToLive(); | $object->SwitchToLive(); | ||||
$object->Load( $event->getEventParam('id') ); | $object->Load( $event->getEventParam('id') ); | ||||
$object->SetField('Password', $email_passwords[$temp_id]); | $object->SetField('Password', $email_passwords[$temp_id]); | ||||
$object->SetField('VerifyPassword', $email_passwords[$temp_id]); | $object->SetField('VerifyPassword', $email_passwords[$temp_id]); | ||||
$this->Application->emailUser($temp_id > 0 ? 'USER.NEW.PASSWORD': 'USER.ADD.BYADMIN', $object->GetID()); | $this->Application->emailUser($temp_id > 0 ? 'USER.NEW.PASSWORD': 'USER.ADD.BYADMIN', $object->GetID()); | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
* Sends restore/validation email event on user email change | * Sends restore/validation email event on user email change | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function sendEmailChangeEvent(kEvent $event) | protected function sendEmailChangeEvent(kEvent $event) | ||||
{ | { | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
$new_email = $object->GetDBField('Email'); | $new_email = $object->GetDBField('Email'); | ||||
$prev_email = $object->GetOriginalField('Email'); | $prev_email = $object->GetOriginalField('Email'); | ||||
if ( !$new_email || ($prev_email == $new_email) ) { | if ( !$new_email || ($prev_email == $new_email) ) { | ||||
return; | return; | ||||
} | } | ||||
Show All 39 Lines | |||||
protected function OnAfterConfigRead(kEvent $event) | protected function OnAfterConfigRead(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterConfigRead($event); | parent::OnAfterConfigRead($event); | ||||
$forms = $this->Application->getUnitOption($event->Prefix, 'Forms'); | $forms = $this->Application->getUnitOption($event->Prefix, 'Forms'); | ||||
$form_fields =& $forms['default']['Fields']; | $form_fields =& $forms['default']['Fields']; | ||||
// 1. arrange user registration countries | // 1. arrange user registration countries | ||||
/** @var SiteHelper $site_helper */ | |||||
$site_helper = $this->Application->recallObject('SiteHelper'); | $site_helper = $this->Application->recallObject('SiteHelper'); | ||||
/* @var $site_helper SiteHelper */ | |||||
$first_country = $site_helper->getDefaultCountry('', false); | $first_country = $site_helper->getDefaultCountry('', false); | ||||
if ($first_country === false) { | if ($first_country === false) { | ||||
$first_country = $this->Application->ConfigValue('User_Default_Registration_Country'); | $first_country = $this->Application->ConfigValue('User_Default_Registration_Country'); | ||||
} | } | ||||
if ($first_country) { | if ($first_country) { | ||||
// update user country dropdown sql | // update user country dropdown sql | ||||
$form_fields['Country']['options_sql'] = preg_replace('/ORDER BY (.*)/', 'ORDER BY IF (CountryStateId = '.$first_country.', 1, 0) DESC, \\1', $form_fields['Country']['options_sql']); | $form_fields['Country']['options_sql'] = preg_replace('/ORDER BY (.*)/', 'ORDER BY IF (CountryStateId = '.$first_country.', 1, 0) DESC, \\1', $form_fields['Country']['options_sql']); | ||||
} | } | ||||
// 2. set default user registration group | // 2. set default user registration group | ||||
$form_fields['PrimaryGroupId']['default'] = $this->Application->ConfigValue('User_NewGroup'); | $form_fields['PrimaryGroupId']['default'] = $this->Application->ConfigValue('User_NewGroup'); | ||||
// 3. allow avatar upload on Front-End | // 3. allow avatar upload on Front-End | ||||
/** @var FileHelper $file_helper */ | |||||
$file_helper = $this->Application->recallObject('FileHelper'); | $file_helper = $this->Application->recallObject('FileHelper'); | ||||
/* @var $file_helper FileHelper */ | |||||
$file_helper->createItemFiles($event->Prefix, true); // create image fields | $file_helper->createItemFiles($event->Prefix, true); // create image fields | ||||
if ($this->Application->isAdminUser) { | if ($this->Application->isAdminUser) { | ||||
// 4. when in administrative console, then create all users with Active status | // 4. when in administrative console, then create all users with Active status | ||||
$form_fields['Status']['default'] = STATUS_ACTIVE; | $form_fields['Status']['default'] = STATUS_ACTIVE; | ||||
// 5. remove groups tab on editing forms when AdvancedUserManagement config variable not set | // 5. remove groups tab on editing forms when AdvancedUserManagement config variable not set | ||||
Show All 34 Lines | |||||
*/ | */ | ||||
function OnMassCloneUsers($event) | function OnMassCloneUsers($event) | ||||
{ | { | ||||
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { | if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
return; | return; | ||||
} | } | ||||
/** @var kTempTablesHandler $temp_handler */ | |||||
$temp_handler = $this->Application->recallObject($event->Prefix.'_TempHandler', 'kTempTablesHandler'); | $temp_handler = $this->Application->recallObject($event->Prefix.'_TempHandler', 'kTempTablesHandler'); | ||||
/* @var $temp_handler kTempTablesHandler */ | |||||
$ids = $this->StoreSelectedIDs($event); | $ids = $this->StoreSelectedIDs($event); | ||||
$temp_handler->CloneItems($event->Prefix, '', $ids); | $temp_handler->CloneItems($event->Prefix, '', $ids); | ||||
$this->clearSelectedIDs($event); | $this->clearSelectedIDs($event); | ||||
} | } | ||||
/** | /** | ||||
* When cloning users, reset password (set random) | * When cloning users, reset password (set random) | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeClone(kEvent $event) | protected function OnBeforeClone(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeClone($event); | parent::OnBeforeClone($event); | ||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
$object->generatePassword(); | $object->generatePassword(); | ||||
$object->SetDBField('ResourceId', 0); // this will reset it | $object->SetDBField('ResourceId', 0); // this will reset it | ||||
// change email because it should be unique | // change email because it should be unique | ||||
$object->NameCopy(Array (), $object->GetID(), 'Email', 'copy%1$s.%2$s'); | $object->NameCopy(Array (), $object->GetID(), 'Email', 'copy%1$s.%2$s'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemLoad(kEvent $event) | protected function OnAfterItemLoad(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterItemLoad($event); | parent::OnAfterItemLoad($event); | ||||
// linking existing images for item with virtual fields | // linking existing images for item with virtual fields | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
/** @var UsersItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object UsersItem */ | |||||
$image_helper->LoadItemImages($object); | $image_helper->LoadItemImages($object); | ||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
$cs_helper->PopulateStates($event, 'State', 'Country'); | $cs_helper->PopulateStates($event, 'State', 'Country'); | ||||
// get user subscription status | // get user subscription status | ||||
$object->SetDBField('SubscribeToMailing', $object->isSubscribed() ? 1 : 0); | $object->SetDBField('SubscribeToMailing', $object->isSubscribed() ? 1 : 0); | ||||
if ( !$this->Application->isAdmin ) { | if ( !$this->Application->isAdmin ) { | ||||
$object->SetFieldOption('FrontLanguage', 'options', $this->getEnabledLanguages()); | $object->SetFieldOption('FrontLanguage', 'options', $this->getEnabledLanguages()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Returns list of enabled languages with their names | * Returns list of enabled languages with their names | ||||
* | * | ||||
* @return Array | * @return Array | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function getEnabledLanguages() | protected function getEnabledLanguages() | ||||
{ | { | ||||
$cache_key = 'user_languages[%LangSerial%]'; | $cache_key = 'user_languages[%LangSerial%]'; | ||||
$ret = $this->Application->getCache($cache_key); | $ret = $this->Application->getCache($cache_key); | ||||
if ( $ret === false ) { | if ( $ret === false ) { | ||||
/** @var kDBList $languages */ | |||||
$languages = $this->Application->recallObject('lang.enabled', 'lang_List'); | $languages = $this->Application->recallObject('lang.enabled', 'lang_List'); | ||||
/* @var $languages kDBList */ | |||||
$ret = Array (); | $ret = Array (); | ||||
foreach ($languages as $language_info) { | foreach ($languages as $language_info) { | ||||
$ret[$languages->GetID()] = $language_info['LocalName']; | $ret[$languages->GetID()] = $language_info['LocalName']; | ||||
} | } | ||||
$this->Application->setCache($cache_key, $ret); | $this->Application->setCache($cache_key, $ret); | ||||
} | } | ||||
return $ret; | return $ret; | ||||
} | } | ||||
/** | /** | ||||
* Save user images | * Save user images | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function saveUserImages($event) | function saveUserImages($event) | ||||
{ | { | ||||
if (!$this->Application->isAdmin) { | if (!$this->Application->isAdmin) { | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// process image upload in virtual fields | // process image upload in virtual fields | ||||
$image_helper->SaveItemImages($object); | $image_helper->SaveItemImages($object); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Makes password required for new users | * Makes password required for new users | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnPreCreate(kEvent $event) | protected function OnPreCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnPreCreate($event); | parent::OnPreCreate($event); | ||||
if ( $event->status != kEvent::erSUCCESS ) { | if ( $event->status != kEvent::erSUCCESS ) { | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$user_type = $this->Application->GetVar('user_type'); | $user_type = $this->Application->GetVar('user_type'); | ||||
if ( $user_type ) { | if ( $user_type ) { | ||||
$object->SetDBField('UserType', $user_type); | $object->SetDBField('UserType', $user_type); | ||||
if ( $user_type == UserType::ADMIN ) { | if ( $user_type == UserType::ADMIN ) { | ||||
$object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_AdminGroup')); | $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_AdminGroup')); | ||||
Show All 9 Lines | |||||
/** | /** | ||||
* Makes password required for new users | * Makes password required for new users | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function _makePasswordRequired($event) | function _makePasswordRequired($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$required_fields = Array ('Password', 'Password_plain', 'VerifyPassword', 'VerifyPassword_plain'); | $required_fields = Array ('Password', 'Password_plain', 'VerifyPassword', 'VerifyPassword_plain'); | ||||
$object->setRequired($required_fields); | $object->setRequired($required_fields); | ||||
} | } | ||||
/** | /** | ||||
* Load item if id is available | * Load item if id is available | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function LoadItem(kEvent $event) | protected function LoadItem(kEvent $event) | ||||
{ | { | ||||
$id = $this->getPassedID($event); | $id = $this->getPassedID($event); | ||||
if ( $id < 0 ) { | if ( $id < 0 ) { | ||||
// when root, guest and so on | // when root, guest and so on | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$object->Clear($id); | $object->Clear($id); | ||||
return; | return; | ||||
} | } | ||||
parent::LoadItem($event); | parent::LoadItem($event); | ||||
} | } | ||||
Show All 37 Lines | |||||
/** | /** | ||||
* Changes user's password and logges him in | * Changes user's password and logges him in | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnResetLostPassword($event) | function OnResetLostPassword($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$event->CallSubEvent('OnUpdate'); | $event->CallSubEvent('OnUpdate'); | ||||
if ( $event->status == kEvent::erSUCCESS ) { | if ( $event->status == kEvent::erSUCCESS ) { | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$user =& $user_helper->getUserObject(); | $user =& $user_helper->getUserObject(); | ||||
$user->Load( $object->GetID() ); | $user->Load( $object->GetID() ); | ||||
if ( $user_helper->checkLoginPermission() ) { | if ( $user_helper->checkLoginPermission() ) { | ||||
$user_helper->loginUserById( $user->GetID() ); | $user_helper->loginUserById( $user->GetID() ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Generates new Root password and email it | * Generates new Root password and email it | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnResetRootPassword($event) | protected function OnResetRootPassword($event) | ||||
{ | { | ||||
/** @var kPasswordFormatter $password_formatter */ | |||||
$password_formatter = $this->Application->recallObject('kPasswordFormatter'); | $password_formatter = $this->Application->recallObject('kPasswordFormatter'); | ||||
/* @var $password_formatter kPasswordFormatter */ | |||||
$new_root_password = kUtil::generatePassword(); | $new_root_password = kUtil::generatePassword(); | ||||
$this->Application->SetConfigValue('RootPass', $password_formatter->hashPassword($new_root_password)); | $this->Application->SetConfigValue('RootPass', $password_formatter->hashPassword($new_root_password)); | ||||
$this->Application->emailAdmin('ROOT.RESET.PASSWORD', null, Array ('password' => $new_root_password)); | $this->Application->emailAdmin('ROOT.RESET.PASSWORD', null, Array ('password' => $new_root_password)); | ||||
$event->SetRedirectParam('reset', 1); | $event->SetRedirectParam('reset', 1); | ||||
$event->SetRedirectParam('pass', 'm'); | $event->SetRedirectParam('pass', 'm'); | ||||
} | } | ||||
/** | /** | ||||
* Perform login of user, selected in Admin Console, on Front-End in a separate window | * Perform login of user, selected in Admin Console, on Front-End in a separate window | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnLoginAs(kEvent $event) | protected function OnLoginAs(kEvent $event) | ||||
{ | { | ||||
/* @var $user_helper UserHelper */ | /** @var UserHelper $user_helper */ | ||||
$user_helper = $this->Application->recallObject('UserHelper'); | $user_helper = $this->Application->recallObject('UserHelper'); | ||||
$user =& $user_helper->getUserObject(); | $user =& $user_helper->getUserObject(); | ||||
$user->Load( $this->Application->GetVar('user_id') ); | $user->Load( $this->Application->GetVar('user_id') ); | ||||
if ( !$user->isLoaded() ) { | if ( !$user->isLoaded() ) { | ||||
return ; | return ; | ||||
} | } | ||||
if ( $user_helper->checkLoginPermission() ) { | if ( $user_helper->checkLoginPermission() ) { | ||||
$user_helper->loginUserById( $user->GetID() ); | $user_helper->loginUserById( $user->GetID() ); | ||||
} | } | ||||
} | } | ||||
} | } |