diff --git a/app/Controllers/Login.php b/app/Controllers/Login.php index 7646d0a24..fbe4988c9 100644 --- a/app/Controllers/Login.php +++ b/app/Controllers/Login.php @@ -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; - } + }*/ } \ No newline at end of file diff --git a/app/Events/Load_config.php b/app/Events/Load_config.php index 8e9784ccd..e50097a0c 100644 --- a/app/Events/Load_config.php +++ b/app/Events/Load_config.php @@ -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'; diff --git a/app/Helpers/migration_helper.php b/app/Helpers/migration_helper.php index 7b41526fa..b610cf533 100644 --- a/app/Helpers/migration_helper.php +++ b/app/Helpers/migration_helper.php @@ -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"); } } } diff --git a/app/Libraries/MY_Validation.php b/app/Libraries/MY_Validation.php index 6764ff30c..bf3f90270 100644 --- a/app/Libraries/MY_Validation.php +++ b/app/Libraries/MY_Validation.php @@ -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()); diff --git a/app/Views/login.php b/app/Views/login.php index fd73c7a77..a1974bc9d 100644 --- a/app/Views/login.php +++ b/app/Views/login.php @@ -38,12 +38,12 @@

lang('Common.software_short')]) ?>

- hasError()): ?> + getErrors())): ?>
listErrors() ?>
- migration->is_latest()): ?> +
config('OSPOS')->settings['application_version']]) ?>