-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from LavaLite/9.x
Installer
- Loading branch information
Showing
2 changed files
with
44 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', '[email protected]'); | ||
$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 | ||
} | ||
|
||
} |