From 2731d2f17c5140c562426b857e9f5d63da5c4593 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Wed, 1 Mar 2023 09:00:24 +0100 Subject: [PATCH] Update the seeders so that they set dynamic passwords by default --- application/controllers/Console.php | 4 ++-- application/controllers/Installation.php | 2 +- application/libraries/Instance.php | 17 ++++++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/application/controllers/Console.php b/application/controllers/Console.php index 705702e4..cf4f9e11 100644 --- a/application/controllers/Console.php +++ b/application/controllers/Console.php @@ -55,9 +55,9 @@ class Console extends EA_Controller { { $this->instance->migrate('fresh'); - $this->instance->seed(); + $password = $this->instance->seed(); - response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "administrator".' . PHP_EOL . PHP_EOL); + response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "' . $password . '".' . PHP_EOL . PHP_EOL); } /** diff --git a/application/controllers/Installation.php b/application/controllers/Installation.php index 3da9b853..2231f409 100644 --- a/application/controllers/Installation.php +++ b/application/controllers/Installation.php @@ -113,7 +113,7 @@ class Installation extends EA_Controller { ], 'settings' => [ 'username' => 'janedoe', - 'password' => 'janedoe', + 'password' => random_string(), 'working_plan' => setting('company_working_plan'), 'notifications' => TRUE, 'google_sync' => FALSE, diff --git a/application/libraries/Instance.php b/application/libraries/Instance.php index 03c1c0ef..05d24767 100644 --- a/application/libraries/Instance.php +++ b/application/libraries/Instance.php @@ -84,17 +84,23 @@ class Instance { /** * Seed the database with test data. + * + * @return string Return's the administrator user password. */ - public function seed() + public function seed(): string { // Settings + setting([ 'company_name' => 'Company Name', 'company_email' => 'info@example.org', 'company_link' => 'https://example.org', ]); + $password = random_string(); + // Admin + $this->CI->admins_model->save([ 'first_name' => 'John', 'last_name' => 'Doe', @@ -102,13 +108,14 @@ class Instance { 'phone_number' => '+10000000000', 'settings' => [ 'username' => 'administrator', - 'password' => 'administrator', + 'password' => $password, 'notifications' => TRUE, 'calendar_view' => CALENDAR_VIEW_DEFAULT ], ]); // Service + $service_id = $this->CI->services_model->save([ 'name' => 'Service', 'duration' => '30', @@ -119,6 +126,7 @@ class Instance { ]); // Provider + $this->CI->providers_model->save([ 'first_name' => 'Jane', 'last_name' => 'Doe', @@ -129,7 +137,7 @@ class Instance { ], 'settings' => [ 'username' => 'janedoe', - 'password' => 'janedoe', + 'password' => random_string(), 'working_plan' => setting('company_working_plan'), 'notifications' => TRUE, 'google_sync' => FALSE, @@ -140,12 +148,15 @@ class Instance { ]); // Customer + $this->CI->customers_model->save([ 'first_name' => 'James', 'last_name' => 'Doe', 'email' => 'james@example.org', 'phone_number' => '+10000000000', ]); + + return $password; } /**