Skip to content

Commit

Permalink
Merge pull request #89 from LavaLite/9.x
Browse files Browse the repository at this point in the history
Installer
  • Loading branch information
georgemjohn authored Mar 6, 2022
2 parents bac464e + e9d8685 commit f58478d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
10 changes: 2 additions & 8 deletions src/Litepie/Install/Installers/Scripts/SetAppKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
46 changes: 42 additions & 4 deletions src/Litepie/Install/Installers/Scripts/SetSuperuserUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
Expand All @@ -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', '[email protected]');
$data['email'] = $this->command->ask('Please enter email for superuser', $email);
$validator = Validator::make($data, ['email' => 'required|email']);

if ($validator->fails()) {
Expand All @@ -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
*
Expand All @@ -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()) {
Expand All @@ -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
}

}

0 comments on commit f58478d

Please sign in to comment.