Skip to content

Commit

Permalink
#4558 - Build-in API support (forms)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Dec 7, 2023
1 parent 9ee9b57 commit b916018
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 16 deletions.
11 changes: 6 additions & 5 deletions template/scripts/BxBaseAccountForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,35 +191,36 @@ public function editAccountInfoForm ($iAccountId)

public function deleteAccountForm ($iAccountId)
{
$bIsApi = bx_is_api();
$oAccount = BxDolAccount::getInstance($iAccountId);
$aAccountInfo = $oAccount ? $oAccount->getInfo() : false;
if (!$aAccountInfo)
return MsgBox(_t('_sys_txt_error_account_is_not_defined'));
return $bIsApi ? _t('_sys_txt_error_account_is_not_defined') : MsgBox(_t('_sys_txt_error_account_is_not_defined'));

// check access
if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = BxDolAccount::isAllowedDelete ($this->_iProfileId, $aAccountInfo)))
return MsgBox($sMsg);
return $bIsApi ? $sMsg : MsgBox($sMsg);

// check and display form
$oForm = $this->getObjectFormDelete();
if(bx_get('content') !== false)
$oForm->aInputs['delete_content']['value'] = (int)bx_get('content');

if (!$oForm)
return MsgBox(_t('_sys_txt_error_occured'));
return $bIsApi ? _t('_sys_txt_error_occured') : MsgBox(_t('_sys_txt_error_occured'));

if (!$oForm->isSubmitted())
unset($aAccountInfo['password']);

$oForm->initChecker($aAccountInfo);

if (!$oForm->isSubmittedAndValid())
return $oForm->getCode();
return $bIsApi ? $oForm->getCodeAPI() : $oForm->getCode();

// delete account
$oAccount = BxDolAccount::getInstance($aAccountInfo['id']);
if (!$oAccount->delete(false === bx_get('delete_content') ? true : (int)$oForm->getCleanValue('delete_content') != 0))
return MsgBox(_t('_sys_txt_error_account_delete'));
return $bIsApi ? _t('_sys_txt_error_account_delete') : MsgBox(_t('_sys_txt_error_account_delete'));

// logout from deleted account
if($iAccountId == getLoggedId())
Expand Down
72 changes: 62 additions & 10 deletions template/scripts/BxBaseServiceAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,29 @@ public function serviceAccountSettingsEmail ($iAccountId = false)
$bApi = bx_is_api();

$mixedResult =$this->_oAccountForms->editAccountEmailSettingsForm($iAccountId);

if($bApi) {
if(is_array($mixedResult))
if(is_array($mixedResult)){
if (isset($mixedResult['form'] )){
return [
bx_api_get_msg($mixedResult['msg']),
bx_api_get_block('form', $mixedResult['form'], [
'ext' => [
'request' => ['url' => '/api.php?r=system/account_settings_email/TemplServiceAccount', 'immutable' => true]
]
])];
}
else{
return [bx_api_get_block('form', $mixedResult, [
'ext' => [
'request' => ['url' => '/api.php?r=system/account_settings_email/TemplServiceAccount', 'immutable' => true]
]
])];
}
}
else
return bx_api_get_msg($mixedResult);
}
return [bx_api_get_msg($mixedResult)];
}

return $mixedResult;
}
Expand Down Expand Up @@ -181,7 +194,7 @@ public function serviceAccountSettingsPassword ($iAccountId = false)
}
}
else
return bx_api_get_msg($mixedResult);
return [bx_api_get_msg($mixedResult)];
}

return $mixedResult;
Expand All @@ -195,17 +208,29 @@ public function serviceAccountSettingsInfo ($iAccountId = false)
$bApi = bx_is_api();

$mixedResult =$this->_oAccountForms->editAccountInfoForm($iAccountId);

if($bApi) {
if(is_array($mixedResult))
if(is_array($mixedResult)){
if (isset($mixedResult['form'] )){
return [
bx_api_get_msg($mixedResult['msg']),
bx_api_get_block('form', $mixedResult['form'], [
'ext' => [
'request' => ['url' => '/api.php?r=system/account_settings_info/TemplServiceAccount', 'immutable' => true]
]
])];
}
else{
return [bx_api_get_block('form', $mixedResult, [
'ext' => [
'request' => ['url' => '/api.php?r=system/account_settings_email/TemplServiceAccount', 'immutable' => true]
'request' => ['url' => '/api.php?r=system/account_settings_info/TemplServiceAccount', 'immutable' => true]
]
])];
}
}
else
return bx_api_get_msg($mixedResult);
}

return [bx_api_get_msg($mixedResult)];
}
return $mixedResult;
}

Expand All @@ -216,7 +241,34 @@ public function serviceAccountSettingsDelAccount ($iAccountId = false)
if (!$iAccountId)
$iAccountId = getLoggedId();

return $this->_oAccountForms->deleteAccountForm($iAccountId);
$bApi = bx_is_api();

$mixedResult = $this->_oAccountForms->deleteAccountForm($iAccountId);

if($bApi) {
if(is_array($mixedResult)){
if (isset($mixedResult['form'] )){
return [
bx_api_get_msg($mixedResult['msg']),
bx_api_get_block('form', $mixedResult['form'], [
'ext' => [
'request' => ['url' => '/api.php?r=system/account_settings_del_account/TemplServiceAccount', 'immutable' => true]
]
])];
}
else{
return [bx_api_get_block('form', $mixedResult, [
'ext' => [
'request' => ['url' => '/api.php?r=system/account_settings_del_account/TemplServiceAccount', 'immutable' => true]
]
])];
}
}
else
return [];
}

return $mixedResult;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion template/scripts/BxBaseServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public function serviceGetSafeServices()
'CreateAccountForm' => 'BxBaseServiceAccount',
'AccountSettingsEmail' => 'BxBaseServiceAccount',
'AccountSettingsPassword' => 'BxBaseServiceAccount',
'AccountSettingsDelAccount' => 'BxBaseServiceAccount',
'AccountSettingsInfo' => 'BxBaseServiceAccount',
'ForgotPassword' => 'BxBaseServiceAccount',
'SwitchProfile' => 'BxBaseServiceAccount',
'AccountProfileSwitcher' => 'BxBaseServiceAccount',
'EmailConfirmation' => 'BxBaseServiceAccount',
'ConfirmEmail' => 'BxBaseServiceAccount',

'CategoriesList' => 'BxBaseServiceCategory',

'Test' => 'BxBaseServiceLogin',
Expand Down

0 comments on commit b916018

Please sign in to comment.