phpnuxbill/system/controllers/register.php
2022-09-07 14:44:04 +07:00

157 lines
6.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* created by iBNuX
**/
if (isset($routes['1'])) {
$do = $routes['1'];
} else {
$do = 'register-display';
}
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';
$otpPath = 'system/uploads/sms/';
switch ($do) {
case 'post':
$otp_code = _post('otp_code');
$username = _post('username');
$fullname = _post('fullname');
$password = _post('password');
$cpassword = _post('cpassword');
$address = _post('address');
$phonenumber = _post('username');
$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>';
}
if ($password != $cpassword) {
$msg .= $_L['PasswordsNotMatch'] . '<br>';
}
if(!empty($_c['sms_url'])){
$otpPath .= sha1($username.$db_password).".txt";
if(file_exists($otpPath) && time()-filemtime($otpPath)>300){
unlink($otpPath);
r2(U . 'register', 's', 'Verification code expired');
}else if(file_exists($otpPath)){
$code = file_get_contents($otpPath);
if($code!=$otp_code){
$ui->assign('username', $username);
$ui->assign('fullname', $fullname);
$ui->assign('address', $address);
$ui->assign('phonenumber', $phonenumber);
$ui->assign('notify', '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span>
</button>
<div>Verification code is Wrong</div></div>');
$ui->display('register-otp.tpl');
exit();
}else{
unlink($otpPath);
}
}else{
r2(U . 'register', 's', 'No Verification code');
}
}
$d = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if ($d) {
$msg .= $_L['account_already_exist'] . '<br>';
}
if ($msg == '') {
$d = ORM::for_table('tbl_customers')->create();
$d->username = $username;
$d->password = $password;
$d->fullname = $fullname;
$d->address = $address;
$d->phonenumber = $phonenumber;
if ($d->save()) {
$user = $d->id();
r2(U . 'login', 's', $_L['Register_Success']);
} else {
$ui->assign('username', $username);
$ui->assign('fullname', $fullname);
$ui->assign('address', $address);
$ui->assign('phonenumber', $phonenumber);
$ui->assign('notify', '<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span>
</button>
<div>Failed to register</div></div>');
r2(U . 'register', 's', 'Failed to register');
}
} else {
$ui->assign('username', $username);
$ui->assign('fullname', $fullname);
$ui->assign('address', $address);
$ui->assign('phonenumber', $phonenumber);
$ui->assign('notify', '<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span>
</button>
<div>' . $msg . '</div></div>');
$ui->display('register.tpl');
}
break;
default:
if(!empty($_c['sms_url'])){
$username = _post('username');
if(!empty($username)){
$d = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if ($d) {
r2(U . 'register', 's', $_L['account_already_exist']);
}
if(!file_exists($otpPath)){
mkdir($otpPath);
touch($otpPath.'index.html');
}
$otpPath .= sha1($username.$db_password).".txt";
if(file_exists($otpPath) && time()-filemtime($otpPath)<120){
$ui->assign('username', $username);
$ui->assign('notify', '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span>
</button>
<div>Please wait '.(120-(time()-filemtime($otpPath))).' seconds before sending another SMS</div></div>');
$ui->display('register-otp.tpl');
}else{
$otp = rand(100000,999999);
file_put_contents($otpPath, $otp);
sendSMS($username,$_c['CompanyName']."\nYour Verification code are: $otp");
$ui->assign('username', $username);
$ui->assign('notify', '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span>
</button>
<div>Verification code has been sent to your phone</div></div>');
$ui->display('register-otp.tpl');
}
}else{
$ui->display('register-rotp.tpl');
}
}else{
$ui->assign('username', "");
$ui->assign('fullname', "");
$ui->assign('address', "");
$ui->assign('otp', false);
$ui->display('register.tpl');
}
break;
}