Custom Fields for registration and Profile, but not yet finished for upload picture

This commit is contained in:
iBNu Maksum
2024-11-19 18:11:34 +07:00
parent 242dda2e99
commit eb970b257a
12 changed files with 311 additions and 11 deletions

View File

@ -75,6 +75,7 @@ switch ($action) {
run_hook('customer_view_edit_profile'); #HOOK
$csrf_token = Csrf::generateAndStoreToken();
$ui->assign('csrf_token', $csrf_token);
$ui->assign('customFields', User::getFormCustomField($ui, false, $user['id']));
$ui->display('customer/profile.tpl');
break;
case 'edit-profile-post':
@ -154,6 +155,8 @@ switch ($action) {
$user->email = $email;
}
User::setFormCustomField($user['id']);
$user->save();
_log('[' . $user['username'] . ']: ' . Lang::T('User Updated Successfully'), 'User', $user['id']);

View File

@ -0,0 +1,53 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
_admin();
$ui->assign('_title', Lang::T('Custom Fields'));
$ui->assign('_system_menu', 'settings');
$action = $routes['1'];
$ui->assign('_admin', $admin);
$fieldPath = $UPLOAD_PATH . DIRECTORY_SEPARATOR . "customer_field.json";
switch ($action) {
case 'save':
print_r($_POST);
$datas = [];
$count = count($_POST['name']);
for($n=0;$n<$count;$n++){
if(!empty($_POST['name'][$n])){
$datas[] = [
'order' => $_POST['order'][$n],
'name' => $_POST['name'][$n],
'type' => $_POST['type'][$n],
'placeholder' => $_POST['placeholder'][$n],
'value' => $_POST['value'][$n],
'register' => $_POST['register'][$n],
'required' => $_POST['required'][$n]
];
}
}
if(count($datas)>1){
usort($datas, function ($item1, $item2) {
return $item1['order'] <=> $item2['order'];
});
}
if(file_put_contents($fieldPath, json_encode($datas))){
r2(U . 'customfield', 's', 'Successfully saved custom fields!');
}else{
r2(U . 'customfield', 'e', 'Failed to save custom fields!');
}
default:
$fields = [];
if(file_exists($fieldPath)){
$fields = json_decode(file_get_contents($fieldPath), true);
}
$ui->assign('fields', $fields);
$ui->display('customfield.tpl');
break;
}

View File

@ -86,7 +86,6 @@ switch ($do) {
}
if ($msg == '') {
run_hook('register_user'); #HOOK
$d = ORM::for_table('tbl_customers')->create();
$d->username = alphanumeric($username, "+_.@-");
$d->password = $password;
@ -96,6 +95,8 @@ switch ($do) {
$d->phonenumber = $phone_number;
if ($d->save()) {
$user = $d->id();
User::setFormCustomField($user);
run_hook('register_user'); #HOOK
r2(U . 'login', 's', Lang::T('Register Success! You can login now'));
} else {
$ui->assign('username', $username);
@ -163,6 +164,7 @@ switch ($do) {
$ui->assign('notify', 'Registration code has been sent to your phone');
$ui->assign('notify_t', 's');
$ui->assign('_title', Lang::T('Register'));
$ui->assign('customFields', User::getFormCustomField($ui, true));
$ui->display('customer/register-otp.tpl');
}
} else {
@ -171,6 +173,7 @@ switch ($do) {
$ui->display('customer/register-rotp.tpl');
}
} else {
$ui->assign('customFields', User::getFormCustomField($ui, true));
$ui->assign('username', "");
$ui->assign('fullname', "");
$ui->assign('address', "");