public function createAccountForm() { // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = BxDolAccount::isAllowedCreate(0))) { return MsgBox($sMsg); } // check and display form $oForm = BxDolForm::getObjectInstance('sys_account', 'sys_account_create'); if (!$oForm) { return MsgBox(_t('_sys_txt_error_occured')); } $oForm->initChecker(); if (!$oForm->isSubmittedAndValid()) { $sCode = $oForm->getCode(); bx_alert('account', 'add_form', 0, 0, array('form_object' => &$oForm, 'form_code' => &$sCode)); return $sCode; } // insert data into database $aValsToAdd = array('email_confirmed' => 0); $iAccountId = $oForm->insert($aValsToAdd); if (!$iAccountId) { if (!$oForm->isValid()) { return $oForm->getCode(); } else { return MsgBox(_t('_sys_txt_error_account_creation')); } } // alert bx_alert('account', 'add', $iAccountId, 0); // if email_confirmation procedure is enabled - send email confirmation letter $oAccount = BxDolAccount::getInstance($iAccountId); if (getParam('sys_email_confirmation') && $oAccount && !$oAccount->isConfirmed()) { $oAccount->sendConfirmationEmail($iAccountId); } // add account and content association bx_import('BxDolProfile'); $iProfileId = BxDolProfile::add(BX_PROFILE_ACTION_MANUAL, $iAccountId, $iAccountId, BX_PROFILE_STATUS_PENDING, 'system'); $oProfile = BxDolProfile::getInstance($iProfileId); // approve profile if auto-approval is enabled and profile status is 'pending' $sStatus = $oProfile->getStatus(); $isAutoApprove = $oForm->isSetPendingApproval() ? false : true; if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove) { $oProfile->approve(BX_PROFILE_ACTION_AUTO); } // perform action BxDolAccount::isAllowedCreate($iProfileId, true); // alert bx_alert('account', 'added', $iAccountId); // login to the created account automatically bx_login($iAccountId); $this->_iProfileId = bx_get_logged_profile_id(); // redirect $this->_redirectAndExit(getParam('sys_redirect_after_account_added'), true, array('account_id' => $iAccountId, 'profile_id' => $iProfileId)); }
protected function onDataAddAfter($iContentId) { $CNF =& $this->_oModule->_oConfig->CNF; // add account and content association $iProfileId = BxDolProfile::add(BX_PROFILE_ACTION_MANUAL, getLoggedId(), $iContentId, BX_PROFILE_STATUS_PENDING, $this->_oModule->getName()); $oProfile = BxDolProfile::getInstance($iProfileId); // approve profile if auto-approval is enabled and profile status is 'pending' $sStatus = $oProfile->getStatus(); $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false; if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove) { $oProfile->approve(BX_PROFILE_ACTION_AUTO); } // set created profile some default membership $iAclLevel = isAdmin() ? MEMBERSHIP_ID_ADMINISTRATOR : getParam($CNF['PARAM_DEFAULT_ACL_LEVEL']); BxDolAcl::getInstance()->setMembership($iProfileId, $iAclLevel, 0, true); // alert bx_alert($this->_oModule->getName(), 'added', $iContentId); // switch context to the created profile $oAccount = BxDolAccount::getInstance(); $oAccount->updateProfileContext($iProfileId); return ''; }
public function onAccountCreated($iAccountId, $isSetPendingApproval, $iAction = BX_PROFILE_ACTION_MANUAL) { // alert bx_alert('account', 'add', $iAccountId, 0); // if email_confirmation procedure is enabled - send email confirmation letter $oAccount = BxDolAccount::getInstance($iAccountId); if (getParam('sys_email_confirmation') && $oAccount && !$oAccount->isConfirmed()) { $oAccount->sendConfirmationEmail($iAccountId); } // add account and content association $iProfileId = BxDolProfile::add(BX_PROFILE_ACTION_MANUAL, $iAccountId, $iAccountId, BX_PROFILE_STATUS_PENDING, 'system'); $oProfile = BxDolProfile::getInstance($iProfileId); // approve profile if auto-approval is enabled and profile status is 'pending' $sStatus = $oProfile->getStatus(); $isAutoApprove = !$isSetPendingApproval; if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove) { $oProfile->approve(BX_PROFILE_ACTION_AUTO); } // alert bx_alert('account', 'added', $iAccountId); // login to the created account automatically bx_login($iAccountId); return $iProfileId; }