Update: New Features "Miscellaneous"

[option] OTP is required when user want to change phone number.

admin can choose option in
 [Miscellaneous]
This commit is contained in:
Focuslinkstech 2024-02-21 00:15:36 +01:00
parent ae83cbeef4
commit a70b954981
4 changed files with 284 additions and 70 deletions

View file

@ -42,17 +42,17 @@ switch ($action) {
$c = ORM::for_table('tbl_user_recharges')->where('username', $user['username'])->find_one();
if ($c) {
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
if($p['is_radius']){
if($c['type'] == 'Hotspot' || ($c['type'] == 'PPPOE' && empty($d['pppoe_password']))){
if ($p['is_radius']) {
if ($c['type'] == 'Hotspot' || ($c['type'] == 'PPPOE' && empty($d['pppoe_password']))) {
Radius::customerUpsert($d, $p);
}
}else{
} else {
$mikrotik = Mikrotik::info($c['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
if ($c['type'] == 'Hotspot') {
Mikrotik::setHotspotUser($client, $c['username'], $npass);
Mikrotik::removeHotspotActiveUser($client, $user['username']);
} else if(empty($d['pppoe_password'])){
Mikrotik::setHotspotUser($client, $c['username'], $npass);
Mikrotik::removeHotspotActiveUser($client, $user['username']);
} else if (empty($d['pppoe_password'])) {
// only change when pppoe_password empty
Mikrotik::setPpoeUser($client, $c['username'], $npass);
Mikrotik::removePpoeActive($client, $user['username']);
@ -122,6 +122,98 @@ switch ($action) {
}
break;
case 'phone-update':
$d = ORM::for_table('tbl_customers')->find_one($user['id']);
if ($d) {
//run_hook('customer_view_edit_profile'); #HOOK
$ui->assign('d', $d);
$ui->display('user-phone-update.tpl');
} else {
r2(U . 'home', 'e', Lang::T('Account Not Found'));
}
break;
case 'phone-update-otp':
$phone = _post('phone');
$username = $user['username'];
$otpPath = 'system/cache/sms/';
if (empty($config['sms_url'])) {
r2(U . 'accounts/phone-update', 'e', Lang::T('SMS server not Available, Please try again later'));
}
if (!empty($config['sms_url'])) {
if (!empty($phone)) {
$d = ORM::for_table('tbl_customers')->where('username', $username)->where('phonenumber', $phone)->find_one();
if ($d) {
r2(U . 'accounts/phone-update', 'e', Lang::T('You cannot use your current phone number'));
}
if (!file_exists($otpPath)) {
mkdir($otpPath);
touch($otpPath . 'index.html');
}
$otpFile = $otpPath . sha1($username . $db_password) . ".txt";
$phoneFile = $otpPath . sha1($username . $db_password) . "_phone.txt";
// expired 10 minutes
if (file_exists($otpFile) && time() - filemtime($otpFile) < 1200) {
r2(U . 'accounts/phone-update', 'e', Lang::T('Please wait ' . (1200 - (time() - filemtime($otpFile))) . ' seconds before sending another SMS'));
} else {
$otp = rand(100000, 999999);
file_put_contents($otpFile, $otp);
file_put_contents($phoneFile, $phone);
Message::sendSMS($phone, $config['CompanyName'] . "\n Your Verification code is: $otp");
r2(U . 'accounts/phone-update', 'e', Lang::T('Verification code has been sent to your phone'));
}
}
}
break;
case 'phone-update-post':
$phone = _post('phone');
$otp_code = _post('otp');
$username = $user['username'];
$otpPath = 'system/cache/sms/';
if (!empty($config['sms_url'])) {
$otpFile = $otpPath . sha1($username . $db_password) . ".txt";
$phoneFile = $otpPath . sha1($username . $db_password) . "_phone.txt";
// expired 10 minutes
if (file_exists($otpFile) && time() - filemtime($otpFile) > 1200) {
unlink($otpFile);
unlink($phoneFile);
r2(U . 'accounts/phone-update', 'e', 'Verification code expired');
} else if (file_exists($otpFile)) {
$code = file_get_contents($otpFile);
if ($code != $otp_code) {
r2(U . 'accounts/phone-update', 'e', 'Wrong Verification code');
exit();
} elseif (file_exists($phoneFile)) {
$savedPhone = file_get_contents($phoneFile);
if ($savedPhone !== $phone) {
r2(U . 'accounts/phone-update', 'e', 'The phone number does not match the one that requested the OTP');
exit();
} else {
unlink($otpFile);
unlink($phoneFile);
}
} else {
r2(U . 'accounts/phone-update', 'e', 'No Verification code');
}
}
}
$d = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if ($d) {
$d->phonenumber = Lang::phoneFormat($phone);
$d->save();
}
r2(U . 'accounts/profile', 's', 'Phone number updated successfully');
break;
default:
$ui->display('a404.tpl');
}

View file

@ -74,11 +74,11 @@
<label class="col-md-2 control-label">Theme</label>
<div class="col-md-6">
<select name="theme" id="theme" class="form-control">
<option value="default" {if $_c['theme'] eq 'default'}selected="selected" {/if}>Default
<option value="default" {if $_c['theme'] eq 'default' }selected="selected" {/if}>Default
</option>
{foreach $themes as $theme}
<option value="{$theme}" {if $_c['theme'] eq $theme}selected="selected" {/if}>
{Lang::ucWords($theme)}</option>
<option value="{$theme}" {if $_c['theme'] eq $theme}selected="selected" {/if}>
{Lang::ucWords($theme)}</option>
{/foreach}
</select>
</div>
@ -103,21 +103,21 @@
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-md-3 control-label"><input type="checkbox" name="hide_mrc" value="yes"
{if $_c['hide_mrc'] eq 'yes'}checked{/if}>
<label class="col-md-3 control-label"><input type="checkbox" name="hide_mrc" value="yes" {if
$_c['hide_mrc'] eq 'yes' }checked{/if}>
{Lang::T('Monthly Registered Customers')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_tms" value="yes"
{if $_c['hide_tms'] eq 'yes'}checked{/if}> {Lang::T('Total Monthly Sales')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_aui" value="yes"
{if $_c['hide_aui'] eq 'yes'}checked{/if}> {Lang::T('All Users Insights')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_al" value="yes"
{if $_c['hide_al'] eq 'yes'}checked{/if}> {Lang::T('Activity Log')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_uet" value="yes"
{if $_c['hide_uet'] eq 'yes'}checked{/if}> {Lang::T('User Expired, Today')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_vs" value="yes"
{if $_c['hide_vs'] eq 'yes'}checked{/if}> Vouchers Stock</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_pg" value="yes"
{if $_c['hide_pg'] eq 'yes'}checked{/if}> Payment Gateway</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_tms" value="yes" {if
$_c['hide_tms'] eq 'yes' }checked{/if}> {Lang::T('Total Monthly Sales')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_aui" value="yes" {if
$_c['hide_aui'] eq 'yes' }checked{/if}> {Lang::T('All Users Insights')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_al" value="yes" {if
$_c['hide_al'] eq 'yes' }checked{/if}> {Lang::T('Activity Log')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_uet" value="yes" {if
$_c['hide_uet'] eq 'yes' }checked{/if}> {Lang::T('User Expired, Today')}</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_vs" value="yes" {if
$_c['hide_vs'] eq 'yes' }checked{/if}> Vouchers Stock</label>
<label class="col-md-2 control-label"><input type="checkbox" name="hide_pg" value="yes" {if
$_c['hide_pg'] eq 'yes' }checked{/if}> Payment Gateway</label>
</div>
</div>
<div class="panel-heading">
@ -132,9 +132,9 @@
<label class="col-md-2 control-label">{Lang::T('Disable Voucher')}</label>
<div class="col-md-6">
<select name="disable_voucher" id="disable_voucher" class="form-control">
<option value="no" {if $_c['disable_voucher'] == 'no'}selected="selected" {/if}>No
<option value="no" {if $_c['disable_voucher']=='no' }selected="selected" {/if}>No
</option>
<option value="yes" {if $_c['disable_voucher'] == 'yes'}selected="selected" {/if}>Yes
<option value="yes" {if $_c['disable_voucher']=='yes' }selected="selected" {/if}>Yes
</option>
</select>
</div>
@ -144,12 +144,12 @@
<label class="col-md-2 control-label">{Lang::T('Voucher Format')}</label>
<div class="col-md-6">
<select name="voucher_format" id="voucher_format" class="form-control">
<option value="up" {if $_c['voucher_format'] == 'up'}selected="selected" {/if}>UPPERCASE
<option value="up" {if $_c['voucher_format']=='up' }selected="selected" {/if}>UPPERCASE
</option>
<option value="low" {if $_c['voucher_format'] == 'low'}selected="selected" {/if}>
<option value="low" {if $_c['voucher_format']=='low' }selected="selected" {/if}>
lowercase
</option>
<option value="rand" {if $_c['voucher_format'] == 'rand'}selected="selected" {/if}>
<option value="rand" {if $_c['voucher_format']=='rand' }selected="selected" {/if}>
RaNdoM
</option>
</select>
@ -157,31 +157,33 @@
<p class="help-block col-md-4">UPPERCASE lowercase RaNdoM</p>
</div>
{if $_c['disable_voucher'] != 'yes'}
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Disable Registration')}</label>
<div class="col-md-6">
<select name="disable_registration" id="disable_registration" class="form-control">
<option value="no" {if $_c['disable_registration'] == 'no'}selected="selected" {/if}>No
</option>
<option value="yes" {if $_c['disable_registration'] == 'yes'}selected="selected" {/if}>
Yes
</option>
</select>
</div>
<p class="help-block col-md-4">
{Lang::T('Customer just Login with Phone number and Voucher Code, Voucher will be password')}
</p>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Disable Registration')}</label>
<div class="col-md-6">
<select name="disable_registration" id="disable_registration" class="form-control">
<option value="no" {if $_c['disable_registration']=='no' }selected="selected" {/if}>No
</option>
<option value="yes" {if $_c['disable_registration']=='yes' }selected="selected" {/if}>
Yes
</option>
</select>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Redirect after Activation</label>
<div class="col-md-6">
<input type="text" class="form-control" id="voucher_redirect" name="voucher_redirect"
placeholder="https://192.168.88.1/status" value="{$voucher_redirect}">
</div>
<p class="help-block col-md-4">
{Lang::T('After Customer activate voucher or login, customer will be redirected to this url')}
</p>
<p class="help-block col-md-4">
{Lang::T('Customer just Login with Phone number and Voucher Code, Voucher will be
password')}
</p>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Redirect after Activation</label>
<div class="col-md-6">
<input type="text" class="form-control" id="voucher_redirect" name="voucher_redirect"
placeholder="https://192.168.88.1/status" value="{$voucher_redirect}">
</div>
<p class="help-block col-md-4">
{Lang::T('After Customer activate voucher or login, customer will be redirected to this
url')}
</p>
</div>
{/if}
</div>
<div class="panel-heading">
@ -223,9 +225,9 @@
<label class="col-md-2 control-label">{Lang::T('Enable System')}</label>
<div class="col-md-6">
<select name="enable_balance" id="enable_balance" class="form-control">
<option value="no" {if $_c['enable_balance'] == 'no'}selected="selected" {/if}>No
<option value="no" {if $_c['enable_balance']=='no' }selected="selected" {/if}>No
</option>
<option value="yes" {if $_c['enable_balance'] == 'yes'}selected="selected" {/if}>Yes
<option value="yes" {if $_c['enable_balance']=='yes' }selected="selected" {/if}>Yes
</option>
</select>
</div>
@ -235,10 +237,10 @@
<label class="col-md-2 control-label">{Lang::T('Allow Transfer')}</label>
<div class="col-md-6">
<select name="allow_balance_transfer" id="allow_balance_transfer" class="form-control">
<option value="no" {if $_c['allow_balance_transfer'] == 'no'}selected="selected" {/if}>
<option value="no" {if $_c['allow_balance_transfer']=='no' }selected="selected" {/if}>
No</option>
<option value="yes" {if $_c['allow_balance_transfer'] == 'yes'}selected="selected"
{/if}>Yes</option>
<option value="yes" {if $_c['allow_balance_transfer']=='yes' }selected="selected" {/if}>
Yes</option>
</select>
</div>
<p class="help-block col-md-4">{Lang::T('Allow balance transfer between customers')}</p>
@ -304,8 +306,8 @@
onchange="document.getElementById('sms_url').value = this.value">
<option value="">Select Router</option>
{foreach $r as $rs}
<option value="{$rs['name']}" {if $rs['name']==$_c['sms_url']}selected{/if}>
{$rs['name']}</option>
<option value="{$rs['name']}" {if $rs['name']==$_c['sms_url']}selected{/if}>
{$rs['name']}</option>
{/foreach}
</select>
</div>
@ -352,9 +354,9 @@
<select name="user_notification_expired" id="user_notification_expired"
class="form-control">
<option value="none">None</option>
<option value="wa" {if $_c['user_notification_expired'] == 'wa'}selected="selected"
<option value="wa" {if $_c['user_notification_expired']=='wa' }selected="selected"
{/if}>Whatsapp</option>
<option value="sms" {if $_c['user_notification_expired'] == 'sms'}selected="selected"
<option value="sms" {if $_c['user_notification_expired']=='sms' }selected="selected"
{/if}>SMS</option>
</select>
</div>
@ -366,9 +368,9 @@
<select name="user_notification_payment" id="user_notification_payment"
class="form-control">
<option value="none">None</option>
<option value="wa" {if $_c['user_notification_payment'] == 'wa'}selected="selected"
<option value="wa" {if $_c['user_notification_payment']=='wa' }selected="selected"
{/if}>Whatsapp</option>
<option value="sms" {if $_c['user_notification_payment'] == 'sms'}selected="selected"
<option value="sms" {if $_c['user_notification_payment']=='sms' }selected="selected"
{/if}>SMS</option>
</select>
</div>
@ -381,9 +383,9 @@
<select name="user_notification_reminder" id="user_notification_reminder"
class="form-control">
<option value="none">None</option>
<option value="wa" {if $_c['user_notification_reminder'] == 'wa'}selected="selected"
<option value="wa" {if $_c['user_notification_reminder']=='wa' }selected="selected"
{/if}>Whatsapp</option>
<option value="sms" {if $_c['user_notification_reminder'] == 'sms'}selected="selected"
<option value="sms" {if $_c['user_notification_reminder']=='sms' }selected="selected"
{/if}>SMS</option>
</select>
</div>
@ -452,6 +454,28 @@
</div>
</div>
</div>
<div class="panel-heading">
<div class="btn-group pull-right">
<button class="btn btn-primary btn-xs" title="save" type="submit"><span
class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span></button>
</div>
{Lang::T('Miscellaneous')}
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('OTP Required')}</label>
<div class="col-md-6">
<select name="allow_phone_otp" id="allow_phone_otp" class="form-control">
<option value="no" {if $_c['allow_phone_otp']=='no' }selected="selected" {/if}>
No</option>
<option value="yes" {if $_c['allow_phone_otp']=='yes' }selected="selected" {/if}>Yes
</option>
</select>
</div>
<p class="help-block col-md-4">{Lang::T('OTP is required when user want to change phone
number')}</p>
</div>
</div>
{* <div class="panel-heading" id="envato">
<div class="btn-group pull-right">
<button class="btn btn-primary btn-xs" title="save" type="submit"><span
@ -484,8 +508,8 @@
<div class="panel-body">
<div class="form-group">
<button class="btn btn-success btn-block waves-effect waves-light"
type="submit">{Lang::T('Save Changes')}</button>
<button class="btn btn-success btn-block waves-effect waves-light" type="submit">{Lang::T('Save
Changes')}</button>
</div>
</div>
@ -511,14 +535,14 @@ add dst-host=*.{$_domain}</pre>
function testWa() {
var target = prompt("Phone number\nSave First before Test", "");
if (target != null) {
window.location.href = '{$_url}settings/app&testWa='+target;
window.location.href = '{$_url}settings/app&testWa=' + target;
}
}
function testSms() {
var target = prompt("Phone number\nSave First before Test", "");
if (target != null) {
window.location.href = '{$_url}settings/app&testSms='+target;
window.location.href = '{$_url}settings/app&testSms=' + target;
}
}

View file

@ -0,0 +1,80 @@
{include file="sections/user-header.tpl"}
<!-- user-phone-update -->
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title">{Lang::T('Change Phone Number')}</h3>
</div>
<div class="box-body">
<div class="form-horizontal">
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Current Number')}</label>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">+</span>
<input type="text" class="form-control" name="phonenumber" id="phonenumber"
value="{$d['phonenumber']}" readonly placeholder="{Lang::T('Phone Number')}">
</div>
</div>
</div>
<form method="post" role="form" action="{$_url}accounts/phone-update-otp">
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('New Number')}</label>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">+</span>
<input type="number" class="form-control" name="phone" id="phone" value="" required
placeholder="{Lang::T('Input your phone number')}">
<span class="input-group-btn">
<button type="submit" class="btn btn-info btn-flat">{Lang::T('Request OTP')}</button>
</span>
</div>
</div>
</div>
</form>
<form method="post" role="form" action="{$_url}accounts/phone-update-post">
<!-- Form 2 -->
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('OTP')}</label>
<div class="col-md-6">
<input type="number" class="form-control" id="otp" name="otp"
placeholder="{Lang::T('Enter OTP that was sent to your phone')}" required>
</div>
</div>
<!-- Hidden field to store the phone number value -->
<input type="hidden" name="phone" id="hidden_phone" required>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success waves-effect waves-light" type="submit"
onclick="return validateForm()">{Lang::T('Update')}</button>
Or <a href="{$_url}home">{Lang::T('Cancel')}</a>
</div>
</div>
</form>
<script>
function validateForm() {
var phoneNumber = document.getElementById("phone").value;
var otp = document.getElementById("otp").value;
if (phoneNumber.trim() === "") {
alert("Phone number is required.");
return false; // Prevent form submission
}
if (otp.trim() === "") {
alert("OTP code is required.");
return false; // Prevent form submission
}
// Set the phone number value in the hidden field
document.getElementById("hidden_phone").value = phoneNumber;
}
</script>
</div>
</div>
</div>
{include file="sections/user-footer.tpl"}

View file

@ -34,6 +34,7 @@
<textarea name="address" id="address" class="form-control">{$d['address']}</textarea>
</div>
</div>
{if $_c['allow_phone_otp'] == 'no'}
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Phone Number')}</label>
<div class="col-md-6">
@ -45,6 +46,23 @@
</div>
</div>
</div>
{elseif $_c['allow_phone_otp'] == 'yes'}
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Phone Number')}</label>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">+</span>
<input type="text" class="form-control" name="phonenumber" id="phonenumber"
value="{$d['phonenumber']}" readonly
placeholder="{if $_c['country_code_phone']!= ''}{$_c['country_code_phone']}{/if} {Lang::T('Phone Number')}">
<span class="input-group-btn">
<a href="{$_url}accounts/phone-update" type="button"
class="btn btn-info btn-flat">{Lang::T('Change')}</a>
</span>
</div>
</div>
</div>
{/if}
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Email')}</label>
<div class="col-md-6">
@ -54,8 +72,8 @@
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success waves-effect waves-light"
type="submit">{Lang::T('Save Changes')}</button>
<button class="btn btn-success waves-effect waves-light" type="submit">{Lang::T('Save
Changes')}</button>
Or <a href="{$_url}home">{Lang::T('Cancel')}</a>
</div>
</div>