184 lines
8.0 KiB
PHP
Raw Normal View History

<?php
2024-02-26 14:38:04 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2022-08-23 16:33:21 +07:00
**/
if (isset($routes['1'])) {
$do = $routes['1'];
} else {
$do = 'register-display';
}
2022-08-23 16:33:21 +07:00
2024-02-26 14:38:04 +07:00
$otpPath = $CACHE_PATH . File::pathFixer('/sms/');
2022-09-07 14:44:04 +07:00
2022-08-23 16:33:21 +07:00
switch ($do) {
case 'post':
2022-09-07 14:44:04 +07:00
$otp_code = _post('otp_code');
2024-07-06 10:32:51 +07:00
$username = alphanumeric(_post('username'), "+_.@-");
2023-07-18 09:51:43 +07:00
$email = _post('email');
$fullname = _post('fullname');
$password = _post('password');
$cpassword = _post('cpassword');
$address = _post('address');
2024-10-28 15:49:44 +07:00
// Separate phone number input if OTP is required
2024-10-18 12:57:59 +07:00
if (!empty($config['sms_url']) && $_c['sms_otp_registration'] == 'yes') {
$phone_number = alphanumeric(_post('phone_number'), "+_.@-");
} else {
$phone_number = $username; // When OTP is not required, treat username as phone number
}
2022-09-01 14:52:32 +07:00
$msg = '';
if (Validator::Length($username, 35, 2) == false) {
$msg .= 'Username should be between 3 to 55 characters' . '<br>';
}
if (Validator::Length($fullname, 36, 2) == false) {
$msg .= 'Full Name should be between 3 to 25 characters' . '<br>';
}
if (!Validator::Length($password, 35, 2)) {
$msg .= 'Password should be between 3 to 35 characters' . '<br>';
}
2023-07-18 09:51:43 +07:00
if (!Validator::Email($email)) {
$msg .= 'Email is not Valid<br>';
}
2022-09-01 14:52:32 +07:00
if ($password != $cpassword) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Passwords does not match') . '<br>';
2022-09-01 14:52:32 +07:00
}
2022-08-23 16:33:21 +07:00
// OTP verification if OTP is enabled
2024-10-18 12:57:59 +07:00
if (!empty($config['sms_url']) && $_c['sms_otp_registration'] == 'yes') {
$otpPath .= sha1($phone_number . $db_pass) . ".txt";
2022-09-18 00:00:40 +07:00
run_hook('validate_otp'); #HOOK
// Expire after 10 minutes
2024-02-26 14:38:04 +07:00
if (file_exists($otpPath) && time() - filemtime($otpPath) > 1200) {
2022-09-07 14:44:04 +07:00
unlink($otpPath);
r2(U . 'register', 's', 'Verification code expired');
2024-02-26 14:38:04 +07:00
} else if (file_exists($otpPath)) {
2022-09-07 14:44:04 +07:00
$code = file_get_contents($otpPath);
2024-02-26 14:38:04 +07:00
if ($code != $otp_code) {
2022-09-07 14:44:04 +07:00
$ui->assign('username', $username);
$ui->assign('fullname', $fullname);
$ui->assign('address', $address);
2023-07-18 09:51:43 +07:00
$ui->assign('email', $email);
$ui->assign('phone_number', $phone_number);
2023-10-24 09:27:51 +07:00
$ui->assign('notify', 'Wrong Verification code');
$ui->assign('notify_t', 'd');
$ui->assign('_title', Lang::T('Register'));
$ui->display('customer/register-otp.tpl');
2022-09-07 14:44:04 +07:00
exit();
2024-02-26 14:38:04 +07:00
} else {
2022-09-07 14:44:04 +07:00
unlink($otpPath);
}
2024-02-26 14:38:04 +07:00
} else {
2022-09-07 14:44:04 +07:00
r2(U . 'register', 's', 'No Verification code');
}
}
// Check if username already exists
2022-09-01 14:52:32 +07:00
$d = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if ($d) {
$msg .= Lang::T('Account already exists') . '<br>';
2022-09-01 14:52:32 +07:00
}
2024-10-28 15:49:44 +07:00
2022-09-01 14:52:32 +07:00
if ($msg == '') {
2022-09-18 00:00:40 +07:00
run_hook('register_user'); #HOOK
2022-09-01 14:52:32 +07:00
$d = ORM::for_table('tbl_customers')->create();
2024-07-06 10:32:51 +07:00
$d->username = alphanumeric($username, "+_.@-");
2022-09-01 14:52:32 +07:00
$d->password = $password;
$d->fullname = $fullname;
$d->address = $address;
2023-07-18 09:51:43 +07:00
$d->email = $email;
$d->phonenumber = $phone_number;
2022-09-01 14:52:32 +07:00
if ($d->save()) {
$user = $d->id();
2024-02-13 13:54:01 +07:00
r2(U . 'login', 's', Lang::T('Register Success! You can login now'));
2022-08-23 16:33:21 +07:00
} else {
$ui->assign('username', $username);
$ui->assign('fullname', $fullname);
$ui->assign('address', $address);
2023-07-18 09:51:43 +07:00
$ui->assign('email', $email);
$ui->assign('phone_number', $phone_number);
2023-10-24 09:27:51 +07:00
$ui->assign('notify', 'Failed to register');
$ui->assign('notify_t', 'd');
$ui->assign('_title', Lang::T('Register'));
2022-09-18 00:00:40 +07:00
run_hook('view_otp_register'); #HOOK
$ui->display('customer/register-rotp.tpl');
2022-08-23 16:33:21 +07:00
}
} else {
$ui->assign('username', $username);
$ui->assign('fullname', $fullname);
$ui->assign('address', $address);
2023-07-18 09:51:43 +07:00
$ui->assign('email', $email);
$ui->assign('phone_number', $phone_number);
2023-10-24 09:27:51 +07:00
$ui->assign('notify', $msg);
$ui->assign('notify_t', 'd');
$ui->assign('_title', Lang::T('Register'));
// Check if OTP is enabled
if (!empty($config['sms_url']) && $_c['sms_otp_registration'] == 'yes') {
// Display register-otp.tpl if OTP is enabled
$ui->display('customer/register-otp.tpl');
} else {
// Display register.tpl if OTP is not enabled
$ui->display('customer/register.tpl');
}
2022-08-23 16:33:21 +07:00
}
break;
default:
2024-10-18 12:57:59 +07:00
if (!empty($config['sms_url']) && $_c['sms_otp_registration'] == 'yes') {
$phone_number = _post('phone_number');
if (!empty($phone_number)) {
$d = ORM::for_table('tbl_customers')->where('username', $phone_number)->find_one();
2022-09-07 14:44:04 +07:00
if ($d) {
r2(U . 'register', 's', Lang::T('Account already exists'));
2022-09-07 14:44:04 +07:00
}
2024-02-26 14:38:04 +07:00
if (!file_exists($otpPath)) {
2022-09-07 14:44:04 +07:00
mkdir($otpPath);
2024-02-26 14:38:04 +07:00
touch($otpPath . 'index.html');
2022-09-07 14:44:04 +07:00
}
$otpPath .= sha1($phone_number . $db_pass) . ".txt";
if (file_exists($otpPath) && time() - filemtime($otpPath) < 600) {
$ui->assign('phone_number', $phone_number);
$ui->assign('notify', 'Please wait ' . (600 - (time() - filemtime($otpPath))) . ' seconds before sending another SMS');
2023-10-24 09:27:51 +07:00
$ui->assign('notify_t', 'd');
$ui->assign('_title', Lang::T('Register'));
$ui->display('customer/register-otp.tpl');
2024-02-26 14:38:04 +07:00
} else {
$otp = rand(100000, 999999);
2022-09-07 14:44:04 +07:00
file_put_contents($otpPath, $otp);
2024-10-21 14:15:39 +07:00
if($config['phone_otp_type'] == 'whatsapp'){
Message::sendWhatsapp($phone_number, $config['CompanyName'] . "\n\n".Lang::T("Registration code")."\n$otp");
2024-10-21 14:15:39 +07:00
}else if($config['phone_otp_type'] == 'both'){
Message::sendWhatsapp($phone_number, $config['CompanyName'] . "\n\n".Lang::T("Registration code")."\n$otp");
Message::sendSMS($phone_number, $config['CompanyName'] . "\n\n".Lang::T("Registration code")."\n$otp");
2024-10-21 14:15:39 +07:00
}else{
Message::sendSMS($phone_number, $config['CompanyName'] . "\n\n".Lang::T("Registration code")."\n$otp");
2024-10-21 14:15:39 +07:00
}
$ui->assign('phone_number', $phone_number);
$ui->assign('notify', 'Registration code has been sent to your phone');
2023-10-24 09:27:51 +07:00
$ui->assign('notify_t', 's');
$ui->assign('_title', Lang::T('Register'));
$ui->display('customer/register-otp.tpl');
2022-09-07 14:44:04 +07:00
}
2024-02-26 14:38:04 +07:00
} else {
$ui->assign('_title', Lang::T('Register'));
2022-09-18 00:00:40 +07:00
run_hook('view_otp_register'); #HOOK
$ui->display('customer/register-rotp.tpl');
2022-09-07 14:44:04 +07:00
}
2024-02-26 14:38:04 +07:00
} else {
2022-09-07 14:44:04 +07:00
$ui->assign('username', "");
$ui->assign('fullname', "");
$ui->assign('address', "");
2023-07-18 09:51:43 +07:00
$ui->assign('email', "");
2022-09-07 14:44:04 +07:00
$ui->assign('otp', false);
$ui->assign('_title', Lang::T('Register'));
2022-09-18 00:00:40 +07:00
run_hook('view_register'); #HOOK
$ui->display('customer/register.tpl');
2022-09-07 14:44:04 +07:00
}
break;
}
?>