added Voucher only Without username

This commit is contained in:
Ibnu Maksum 2024-07-23 12:03:13 +07:00
parent 922f24b630
commit 8061acbf9e
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
5 changed files with 257 additions and 115 deletions

View File

@ -138,8 +138,9 @@
<td class="content-block" <td class="content-block"
style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;" style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;"
valign="top" align="center"> valign="top" align="center">
<p>
<span class="apple-link" <span class="apple-link"
style="color: #9a9ea6; font-size: 16px; text-align: center;">[[Company_Address]]</span> style="color: #9a9ea6; font-size: 16px; text-align: center;">[[Company_Address]]</span></p>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -44,8 +44,12 @@ class Package
_alert(Lang::T('This account status') . ' : ' . Lang::T($c['status']), 'danger', ""); _alert(Lang::T('This account status') . ' : ' . Lang::T($c['status']), 'danger', "");
} }
}else{ }else{
$c['username'] = $channel; $c = [
$c['fullname'] = $gateway; 'fullname' => $gateway,
'email' => '',
'username' => $channel,
'password' => $channel,
];
} }
$add_cost = 0; $add_cost = 0;
@ -146,7 +150,8 @@ class Package
/** /**
* 1 Customer only can have 1 PPPOE and 1 Hotspot Plan, 1 prepaid and 1 postpaid * 1 Customer only can have 1 PPPOE and 1 Hotspot Plan, 1 prepaid and 1 postpaid
*/ */
$b = ORM::for_table('tbl_user_recharges')
$query = ORM::for_table('tbl_user_recharges')
->select('tbl_user_recharges.id', 'id') ->select('tbl_user_recharges.id', 'id')
->select('customer_id') ->select('customer_id')
->select('username') ->select('username')
@ -162,14 +167,18 @@ class Package
->select('tbl_user_recharges.type', 'type') ->select('tbl_user_recharges.type', 'type')
->select('admin_id') ->select('admin_id')
->select('prepaid') ->select('prepaid')
->where('customer_id', $id_customer)
->where('tbl_user_recharges.routers', $router_name) ->where('tbl_user_recharges.routers', $router_name)
->where('tbl_user_recharges.Type', $p['type']) ->where('tbl_user_recharges.Type', $p['type'])
# PPPOE or Hotspot only can have 1 per customer prepaid or postpaid # PPPOE or Hotspot only can have 1 per customer prepaid or postpaid
# because 1 customer can have 1 PPPOE and 1 Hotspot Plan in mikrotik # because 1 customer can have 1 PPPOE and 1 Hotspot Plan in mikrotik
//->where('prepaid', $p['prepaid']) //->where('prepaid', $p['prepaid'])
->left_outer_join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id')) ->left_outer_join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id'));
->find_one(); if($isVoucher){
$query->where('username', $c['username']);
}else{
$query->where('customer_id', $id_customer);
}
$b = $query->find_one();
run_hook("recharge_user"); run_hook("recharge_user");

View File

@ -56,134 +56,235 @@ switch ($do) {
break; break;
case 'activation': case 'activation':
$voucher = _post('voucher'); if (!empty(_post('voucher_only'))) {
$username = _post('username'); $voucher = _post('voucher_only');
$v1 = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one(); $tur = ORM::for_table('tbl_user_recharges')
if ($v1) { ->where('username', $voucher)
// voucher exists, check customer exists or not ->where('customer_id', '0') // Voucher Only will make customer ID as 0
$user = ORM::for_table('tbl_customers')->where('username', $username)->find_one(); ->find_one();
if (!$user) { if ($tur) {
$d = ORM::for_table('tbl_customers')->create(); if ($tur['status'] == 'off') {
$d->username = alphanumeric($username, "+_.@-"); _alert(Lang::T('Internet Voucher Expired'), 'danger', "login");
$d->password = $voucher;
$d->fullname = '';
$d->address = '';
$d->email = '';
$d->phonenumber = (strlen($username) < 21) ? $username : '';
if ($d->save()) {
$user = ORM::for_table('tbl_customers')->where('username', $username)->find_one($d->id());
if (!$user) {
r2(U . 'login', 'e', Lang::T('Voucher activation failed'));
}
} else {
_alert(Lang::T('Login Successful'), 'success', "dashboard");
r2(U . 'login', 'e', Lang::T('Voucher activation failed') . '.');
} }
} $p = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one();
if ($v1['status'] == 0) { if ($p) {
$oldPass = $user['password']; $dvc = Package::getDevice($p);
// change customer password to voucher code if ($_app_stage != 'demo') {
$user->password = $voucher; if (file_exists($dvc)) {
$user->save(); if (file_exists($dvc)) {
// voucher activation require_once $dvc;
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Voucher", $voucher)) { $c = [
$v1->status = "1"; 'fullname' => "Voucher",
$v1->user = $user['username']; 'email' => '',
$v1->save(); 'username' => $voucher,
$user->last_login = date('Y-m-d H:i:s'); 'password' => $voucher,
$user->save(); ];
// add customer to mikrotik (new $p['device'])->add_customer($c, $p);
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try {
$p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one();
$dvc = Package::getDevice($p);
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']);
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
} else { } else {
r2(U . "login", 's', Lang::T("Voucher activation success, you are connected to internet")); new Exception(Lang::T("Devices Not Found"));
} }
} catch (Exception $e) {
if (!empty($config['voucher_redirect'])) { if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login")); r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else { } else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
} }
} else {
new Exception(Lang::T("Devices Not Found"));
} }
} }
if (!empty($config['voucher_redirect'])) { if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login")); _alert(Lang::T("Voucher activation success, now you can login"), 'danger', $config['voucher_redirect']);
} else { } else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); r2(U . "login", 's', Lang::T("Voucher activation success, you are connected to internet"));
} }
} else { } else {
// if failed to recharge, restore old password _alert(Lang::T('Internet Plan Expired'), 'danger', "login");
$user->password = $oldPass;
$user->save();
r2(U . 'login', 'e', Lang::T("Failed to activate voucher"));
} }
} else { } else {
// used voucher $v = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one();
// check if voucher used by this username if (!$v) {
if ($v1['user'] == $user['username']) { _alert(Lang::T('Voucher invalid'), 'danger', "login");
$user->last_login = date('Y-m-d H:i:s'); }
$user->save(); if ($v['status'] == 0) {
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { if (Package::rechargeUser(0, $v['routers'], $v['id_plan'], "Voucher", $voucher)) {
try { $v->status = "1";
$p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one(); $v->save();
$dvc = Package::getDevice($p); $tur = ORM::for_table('tbl_user_recharges')->where('username', $voucher)->find_one();
if ($_app_stage != 'demo') { if ($tur) {
if (file_exists($dvc)) { $p = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one();
require_once $dvc; if ($p) {
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']); $dvc = Package::getDevice($p);
if (!empty($config['voucher_redirect'])) { if ($_app_stage != 'demo') {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login")); if (file_exists($dvc)) {
if (file_exists($dvc)) {
require_once $dvc;
$c = [
'fullname' => "Voucher",
'email' => '',
'username' => $voucher,
'password' => $voucher,
];
(new $p['device'])->add_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else { } else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); new Exception(Lang::T("Devices Not Found"));
} }
}
if (!empty($config['voucher_redirect'])) {
_alert(Lang::T("Voucher activation success, now you can login"), 'danger', $config['voucher_redirect']);
} else { } else {
new Exception(Lang::T("Devices Not Found")); r2(U . "login", 's', Lang::T("Voucher activation success, you are connected to internet"));
}
} else {
_alert(Lang::T('Internet Plan Expired'), 'danger', "login");
}
} else {
_alert(Lang::T('Voucher activation failed'), 'danger', "login");
}
} else {
_alert(Lang::T('Voucher activation failed'), 'danger', "login");
}
} else {
_alert(Lang::T('Internet Voucher Expired'), 'danger', "login");
}
}
} else {
$voucher = _post('voucher');
$username = _post('username');
$v1 = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one();
if ($v1) {
// voucher exists, check customer exists or not
$user = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if (!$user) {
$d = ORM::for_table('tbl_customers')->create();
$d->username = alphanumeric($username, "+_.@-");
$d->password = $voucher;
$d->fullname = '';
$d->address = '';
$d->email = '';
$d->phonenumber = (strlen($username) < 21) ? $username : '';
if ($d->save()) {
$user = ORM::for_table('tbl_customers')->where('username', $username)->find_one($d->id());
if (!$user) {
r2(U . 'login', 'e', Lang::T('Voucher activation failed'));
}
} else {
_alert(Lang::T('Login Successful'), 'success', "dashboard");
r2(U . 'login', 'e', Lang::T('Voucher activation failed') . '.');
}
}
if ($v1['status'] == 0) {
$oldPass = $user['password'];
// change customer password to voucher code
$user->password = $voucher;
$user->save();
// voucher activation
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Voucher", $voucher)) {
$v1->status = "1";
$v1->user = $user['username'];
$v1->save();
$user->last_login = date('Y-m-d H:i:s');
$user->save();
// add customer to mikrotik
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try {
$p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one();
$dvc = Package::getDevice($p);
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']);
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, you are connected to internet"));
}
} catch (Exception $e) {
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
} }
} }
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
// if failed to recharge, restore old password
$user->password = $oldPass;
$user->save();
r2(U . 'login', 'e', Lang::T("Failed to activate voucher"));
}
} else {
// used voucher
// check if voucher used by this username
if ($v1['user'] == $user['username']) {
$user->last_login = date('Y-m-d H:i:s');
$user->save();
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try {
$p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one();
$dvc = Package::getDevice($p);
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']);
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} catch (Exception $e) {
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
}
} else {
if (!empty($config['voucher_redirect'])) { if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
} else { } else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
} }
} catch (Exception $e) {
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} }
} else { } else {
if (!empty($config['voucher_redirect'])) { // voucher used by other customer
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); r2(U . 'login', 'e', Lang::T('Voucher Not Valid'));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} }
} else {
// voucher used by other customer
r2(U . 'login', 'e', Lang::T('Voucher Not Valid'));
} }
} else {
_msglog('e', Lang::T('Invalid Username or Password'));
r2(U . 'login');
} }
} else {
_msglog('e', Lang::T('Invalid Username or Password'));
r2(U . 'login');
} }
default: default:
run_hook('customer_view_login'); #HOOK run_hook('customer_view_login'); #HOOK

View File

@ -653,7 +653,11 @@
"Http_Chap": "Http-Chap", "Http_Chap": "Http-Chap",
"Hotspot_Authentication_Method__Make_sure_you_have_changed_your_hotspot_login_page_": "Hotspot Authentication Method. Make sure you have changed your hotspot login page.", "Hotspot_Authentication_Method__Make_sure_you_have_changed_your_hotspot_login_page_": "Hotspot Authentication Method. Make sure you have changed your hotspot login page.",
"Business": "Business", "Business": "Business",
"": "",
"Source": "Source", "Source": "Source",
"Destination": "Destination" "Destination": "Destination",
"Activate_Voucher": "Activate Voucher",
"Voucher_invalid": "Voucher invalid",
"Account_Not_Found": "Account Not Found",
"Voucher_activation_success__now_you_can_login": "Voucher activation success, now you can login",
"Internet_Voucher_Expired": "Internet Voucher Expired"
} }

View File

@ -60,10 +60,12 @@
<div class="form-group"> <div class="form-group">
<label>{Lang::T('Enter voucher code here')}</label> <label>{Lang::T('Enter voucher code here')}</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" id="voucher" name="voucher" required value="{$code}" <input type="text" class="form-control" id="voucher" name="voucher" required
placeholder="{Lang::T('Enter voucher code here')}"> value="{$code}" placeholder="{Lang::T('Enter voucher code here')}">
<span class="input-group-btn"> <span class="input-group-btn">
<a class="btn btn-default" href="{APP_URL}/scan/?back={urlencode($_url)}{urlencode("login&code=")}"><i class="glyphicon glyphicon-qrcode"></i></a> <a class="btn btn-default"
href="{APP_URL}/scan/?back={urlencode($_url)}{urlencode("login&code=")}"><i
class="glyphicon glyphicon-qrcode"></i></a>
</span> </span>
</div> </div>
</div> </div>
@ -73,15 +75,40 @@
class="btn btn-primary">{Lang::T('Login / Activate Voucher')}</button> class="btn btn-primary">{Lang::T('Login / Activate Voucher')}</button>
</div> </div>
</div> </div>
<br>
<center>
<a href="./pages/Privacy_Policy.html" target="_blank">Privacy</a>
&bull;
<a href="./pages/Terms_of_Conditions.html" target="_blank">ToC</a>
</center>
</form> </form>
</div> </div>
</div> </div>
<div class="panel panel-primary">
<div class="panel-heading">{Lang::T('Activate Voucher')}</div>
<div class="panel-body">
<form action="{$_url}login/activation" method="post">
<div class="form-group">
<label>{Lang::T('Enter voucher code here')}</label>
<div class="input-group">
<input type="text" class="form-control" id="voucher_only" name="voucher_only" required
value="{$code}" placeholder="{Lang::T('Enter voucher code here')}">
<span class="input-group-btn">
<a class="btn btn-default"
href="{APP_URL}/scan/?back={urlencode($_url)}{urlencode("login&code=")}"><i
class="glyphicon glyphicon-qrcode"></i></a>
</span>
</div>
</div>
<div class="btn-group btn-group-justified mb15">
<div class="btn-group">
<button type="submit"
class="btn btn-primary">{Lang::T('Activate Voucher')}</button>
</div>
</div>
</form>
</div>
</div>
<br>
<center>
<a href="./pages/Privacy_Policy.html" target="_blank">Privacy</a>
&bull;
<a href="./pages/Terms_of_Conditions.html" target="_blank">ToC</a>
</center>
</div> </div>
</div> </div>
</div> </div>