mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-10 18:09:30 -04:00
CI4 fixes
- validation - migration fixes - string interpolation - oh my
This commit is contained in:
committed by
Steve Ireland
parent
e4d0497633
commit
52c8511d8d
@@ -2,13 +2,17 @@
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\MY_Migration;
|
||||
use App\Models\Employee;
|
||||
use Config\Services;
|
||||
|
||||
/**
|
||||
* @property employee employee
|
||||
*/
|
||||
class Login extends BaseController
|
||||
{
|
||||
protected $helpers = ['form'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->employee = model('Employee');
|
||||
@@ -19,7 +23,17 @@ class Login extends BaseController
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this->validate(['username' => 'required']))
|
||||
$migration = new MY_Migration();
|
||||
$data = [
|
||||
'validation' => Services::validation(),
|
||||
'latest_version' => $migration->is_latest()];
|
||||
|
||||
if(strtolower($this->request->getMethod()) !== 'post')
|
||||
{
|
||||
echo view('login', $data);
|
||||
}
|
||||
|
||||
if(!$this->validate(['username' => 'required|login_check']))
|
||||
{
|
||||
echo view('login', ['validation' => $this->validator->getErrors()]);
|
||||
}
|
||||
@@ -30,7 +44,7 @@ class Login extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function login_check($username): bool
|
||||
/* public function login_check(string $username): bool
|
||||
{
|
||||
if(!$this->installation_check())
|
||||
{
|
||||
@@ -115,5 +129,5 @@ class Login extends BaseController
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -42,7 +42,9 @@ class Load_config
|
||||
}
|
||||
|
||||
//Language
|
||||
helper('locale');
|
||||
$language_exists = file_exists('../app/Language/' . current_language_code());
|
||||
|
||||
if(current_language_code() == null || current_language() == null || !$language_exists) //TODO: current_language() is undefined
|
||||
{
|
||||
$config->language = 'english';
|
||||
|
||||
@@ -11,12 +11,6 @@ function execute_script(string $path): void
|
||||
error_log("Migrating to $version (file: $path)");
|
||||
|
||||
$sql = file_get_contents($path);
|
||||
|
||||
/*
|
||||
CI migration only allows you to run one statement at a time.
|
||||
This small script splits the statements allowing you to run them all in one go.
|
||||
*/
|
||||
|
||||
$sqls = explode(';', $sql);
|
||||
array_pop($sqls);
|
||||
|
||||
@@ -24,13 +18,13 @@ function execute_script(string $path): void
|
||||
|
||||
foreach($sqls as $statement)
|
||||
{
|
||||
$statement = $statement . ';'; //TODO: Can use string interpolation here
|
||||
$statement = "$statement;";
|
||||
|
||||
if(!$db->simpleQuery($statement))
|
||||
{
|
||||
foreach($db->error() as $error)
|
||||
{
|
||||
error_log('error: ' . $error); //TODO: Can use string interpolation here
|
||||
error_log("error: $error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ class MY_Validation extends Validation
|
||||
$migration = Services::migrations();
|
||||
$employee = model(Employee::class);
|
||||
|
||||
$password = $this->request->getPost('password'); //TODO: This needs to get passed as a parameter in some way
|
||||
$password = $this->request->getPost('password');
|
||||
|
||||
if(!$this->_installation_check()) //TODO: Hungarian notation
|
||||
if(!$this->installation_check())
|
||||
{
|
||||
$error = lang('Login.invalid_installation');
|
||||
|
||||
@@ -44,10 +44,22 @@ class MY_Validation extends Validation
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(config('OSPOS')->settings['gcaptcha_enable'])
|
||||
{
|
||||
$g_recaptcha_response = $this->request->getPost('g-recaptcha-response');
|
||||
|
||||
if(!$this->gcaptcha_check($g_recaptcha_response))
|
||||
{
|
||||
$this->validator->setMessage('login_check', lang('login_invalid_gcaptcha'));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
private function _installation_check() //TODO: Hungarian Notation
|
||||
private function installation_check() //TODO: Hungarian Notation
|
||||
{
|
||||
// get PHP extensions and check that the required ones are installed
|
||||
$extensions = implode(', ', get_loaded_extensions());
|
||||
|
||||
@@ -38,12 +38,12 @@
|
||||
<section class="box-login d-flex flex-column justify-content-center align-items-center p-md-4">
|
||||
<?php echo form_open('login') ?>
|
||||
<h3 class="text-center m-0"><?php echo lang('Login.welcome', ['install_name' => lang('Common.software_short')]) ?></h3>
|
||||
<?php if ($validation->hasError()): ?>
|
||||
<?php if (!empty($validation->getErrors())): ?>
|
||||
<div class="alert alert-danger mt-3">
|
||||
<?php echo $validation->listErrors() ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!$this->migration->is_latest()): ?>
|
||||
<?php if(!$latest_version): ?>
|
||||
<div class="alert alert-info mt-3">
|
||||
<?php echo lang('Login.migration_needed', ['version' => config('OSPOS')->settings['application_version']]) ?>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user