From e9d8685969c8cabe00ae7a408e811ff86787cb34 Mon Sep 17 00:00:00 2001 From: George John Date: Sun, 6 Mar 2022 15:01:52 +0400 Subject: [PATCH] Installer - superuser login updates. - App key generation issue fixed. --- .../Install/Installers/Scripts/SetAppKey.php | 10 +--- .../Installers/Scripts/SetSuperuserUser.php | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/Litepie/Install/Installers/Scripts/SetAppKey.php b/src/Litepie/Install/Installers/Scripts/SetAppKey.php index 9040c9f3..fcc6751f 100644 --- a/src/Litepie/Install/Installers/Scripts/SetAppKey.php +++ b/src/Litepie/Install/Installers/Scripts/SetAppKey.php @@ -16,13 +16,7 @@ class SetAppKey implements SetupScript */ public function fire(Command $command) { - if ($command->option('verbose')) { - $command->info('Genarating application key...'); - $command->call('key:generate', ['--force' => true]); - - return; - } - - $command->call('key:generate', ['--force' => true]); + $command->info('Genarating application key...'); + $command->call('key:generate', ['--force' => true, '--show' => true]); } } diff --git a/src/Litepie/Install/Installers/Scripts/SetSuperuserUser.php b/src/Litepie/Install/Installers/Scripts/SetSuperuserUser.php index 8c0f4a20..03a000fb 100644 --- a/src/Litepie/Install/Installers/Scripts/SetSuperuserUser.php +++ b/src/Litepie/Install/Installers/Scripts/SetSuperuserUser.php @@ -3,12 +3,15 @@ namespace Litepie\Install\Installers\Scripts; use Illuminate\Console\Command; +use Illuminate\Support\Str; use Litepie\Install\Installers\SetupScript; use Litepie\User\Models\User; use Validator; class SetSuperuserUser implements SetupScript { + private $domain = null; + /** * Fire the install script. * @@ -25,11 +28,12 @@ public function fire(Command $command) $this->command = $command; config(['litepie.user.user' => [ - 'table' => 'users', + 'table' => 'users', 'fillable' => ['password', 'email'], ]]); $user = User::find(1); + $user->email = $this->askDomain(); $user->email = $this->askUserEmail(); $user->password = $this->askUserPassword(); $user->save(); @@ -42,8 +46,12 @@ public function fire(Command $command) */ private function askUserEmail() { + if (empty($this->domain)) { + $this->askDomain(); + } + $email = 'superuser@' . $this->domain; do { - $data['email'] = $this->command->ask('Please enter email for superuser', 'superuser@lavalite.org'); + $data['email'] = $this->command->ask('Please enter email for superuser', $email); $validator = Validator::make($data, ['email' => 'required|email']); if ($validator->fails()) { @@ -54,6 +62,27 @@ private function askUserEmail() return $data['email']; } + /** + * @param $gitignorePath + * + * @return bool + */ + private function askDomain() + { + do { + $domain = $this->command->ask('Please enter your domain name', 'lavalite.org'); + + $isValid = $this->isDomainValid($domain); + + if (!$isValid) { + $this->command->error('Please enter a valid domain name.'); + } + } while (!$isValid); + + return $this->domain = $domain; + + } + /** * @param $gitignorePath * @@ -62,9 +91,10 @@ private function askUserEmail() private function askUserPassword() { do { - $data['password'] = $this->command->secret('Please enter password for superuser'); + $password = Str::random(8); + $data['password'] = $this->command->ask('Please enter password for superuser', $password); $validator = Validator::make($data, [ - 'password' => 'min:6|max:30', + 'password' => 'required|min:6|max:30', ]); if ($validator->fails()) { @@ -74,4 +104,12 @@ private function askUserPassword() return bcrypt($data['password']); } + + public function isDomainValid($domain) + { + return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain) //valid chars check + && preg_match("/^.{1,253}$/", $domain) //overall length check + && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain)); //length of each label + } + }