phpnuxbill/system/controllers/accounts.php

128 lines
5 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2017-03-11 03:51:06 +08:00
/**
2023-10-12 16:47:45 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
2023-10-12 16:55:42 +08:00
* by https://t.me/ibnux
**/
2023-10-12 16:47:45 +08:00
2017-03-11 03:51:06 +08:00
_auth();
2024-02-13 14:54:01 +08:00
$ui->assign('_title', Lang::T('My Account'));
2017-03-11 03:51:06 +08:00
$ui->assign('_system_menu', 'accounts');
$action = $routes['1'];
$user = User::_info();
$ui->assign('_user', $user);
switch ($action) {
2022-08-23 17:33:21 +08:00
2017-03-11 03:51:06 +08:00
case 'change-password':
2022-09-18 01:00:40 +08:00
run_hook('customer_view_change_password'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('user-change-password.tpl');
break;
case 'change-password-post':
$password = _post('password');
2022-09-17 23:34:55 +08:00
run_hook('customer_change_password'); #HOOK
if ($password != '') {
$d = ORM::for_table('tbl_customers')->where('username', $user['username'])->find_one();
if ($d) {
2017-03-11 03:51:06 +08:00
$d_pass = $d['password'];
$npass = _post('npass');
2017-03-11 03:51:06 +08:00
$cnpass = _post('cnpass');
2022-08-23 17:33:21 +08:00
if (Password::_uverify($password, $d_pass) == true) {
if (!Validator::Length($npass, 15, 2)) {
r2(U . 'accounts/change-password', 'e', 'New Password must be 3 to 14 character');
2017-03-11 03:51:06 +08:00
}
if ($npass != $cnpass) {
r2(U . 'accounts/change-password', 'e', 'Both Password should be same');
2017-03-11 03:51:06 +08:00
}
$c = ORM::for_table('tbl_user_recharges')->where('username', $user['username'])->find_one();
if ($c) {
2023-10-04 17:25:21 +08:00
$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']))){
2023-10-12 14:27:44 +08:00
Radius::customerUpsert($d, $p);
2022-09-07 17:11:35 +08:00
}
2023-10-04 17:25:21 +08:00
}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'])){
// only change when pppoe_password empty
Mikrotik::setPpoeUser($client, $c['username'], $npass);
Mikrotik::removePpoeActive($client, $user['username']);
2022-09-07 17:11:35 +08:00
}
}
2023-10-04 17:25:21 +08:00
}
$d->password = $npass;
$d->save();
2022-08-23 17:33:21 +08:00
2024-02-13 14:54:01 +08:00
_msglog('s', Lang::T('Password changed successfully, Please login again'));
2023-10-04 17:25:21 +08:00
_log('[' . $user['username'] . ']: Password changed successfully', 'User', $user['id']);
2022-08-23 17:33:21 +08:00
2023-10-04 17:25:21 +08:00
r2(U . 'login');
} else {
2024-02-13 14:54:01 +08:00
r2(U . 'accounts/change-password', 'e', Lang::T('Incorrect Current Password'));
2017-03-11 03:51:06 +08:00
}
} else {
2024-02-13 14:54:01 +08:00
r2(U . 'accounts/change-password', 'e', Lang::T('Incorrect Current Password'));
2017-03-11 03:51:06 +08:00
}
} else {
2024-02-13 14:54:01 +08:00
r2(U . 'accounts/change-password', 'e', Lang::T('Incorrect Current Password'));
2017-03-11 03:51:06 +08:00
}
break;
case 'profile':
$d = ORM::for_table('tbl_customers')->find_one($user['id']);
if ($d) {
2022-09-18 01:00:40 +08:00
run_hook('customer_view_edit_profile'); #HOOK
$ui->assign('d', $d);
2017-03-11 03:51:06 +08:00
$ui->display('user-profile.tpl');
} else {
r2(U . 'home', 'e', $_L['Account_Not_Found']);
2017-03-11 03:51:06 +08:00
}
break;
case 'edit-profile-post':
$fullname = _post('fullname');
$address = _post('address');
2022-10-16 00:18:24 +08:00
$email = _post('email');
2017-03-11 03:51:06 +08:00
$phonenumber = _post('phonenumber');
2022-09-17 23:34:55 +08:00
run_hook('customer_edit_profile'); #HOOK
2017-03-11 03:51:06 +08:00
$msg = '';
if (Validator::Length($fullname, 31, 2) == false) {
$msg .= 'Full Name should be between 3 to 30 characters' . '<br>';
2017-03-11 03:51:06 +08:00
}
if (Validator::UnsignedNumber($phonenumber) == false) {
$msg .= 'Phone Number must be a number' . '<br>';
}
$d = ORM::for_table('tbl_customers')->find_one($user['id']);
if ($d) {
} else {
2024-02-13 14:54:01 +08:00
$msg .= Lang::T('Data Not Found') . '<br>';
2017-03-11 03:51:06 +08:00
}
if ($msg == '') {
2017-03-11 03:51:06 +08:00
$d->fullname = $fullname;
$d->address = $address;
$d->email = $email;
$d->phonenumber = $phonenumber;
2017-03-11 03:51:06 +08:00
$d->save();
2022-08-23 17:33:21 +08:00
2024-02-13 14:54:01 +08:00
_log('[' . $user['username'] . ']: ' . Lang::T('User Updated Successfully'), 'User', $user['id']);
r2(U . 'accounts/profile', 's', Lang::T('User Updated Successfully'));
} else {
2017-03-11 03:51:06 +08:00
r2(U . 'accounts/profile', 'e', $msg);
}
break;
2022-08-23 17:33:21 +08:00
2017-03-11 03:51:06 +08:00
default:
2023-09-27 16:01:48 +08:00
$ui->display('a404.tpl');
}