blessing-skin-server/app/Console/Commands/BsInstallCommand.php

47 lines
1.5 KiB
PHP
Raw Normal View History

2019-03-23 16:36:54 +08:00
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
2019-08-09 10:13:55 +08:00
class BsInstallCommand extends Command
2019-03-23 16:36:54 +08:00
{
protected $signature = 'bs:install {email} {password} {nickname}';
protected $description = 'Execute installation and create a super administrator.';
public function handle()
{
if (\App\Http\Controllers\SetupController::checkTablesExist()) {
$this->info('You have installed Blessing Skin Server. Nothing to do.');
2019-04-19 19:36:36 +08:00
return;
}
2019-08-09 11:20:36 +08:00
$this->call('key:generate');
2019-03-23 16:36:54 +08:00
$this->call('salt:random');
$this->call('migrate', ['--force' => true]);
$this->call('jwt:secret', ['--no-interaction' => true]);
$this->call('passport:keys', ['--no-interaction' => true]);
2019-03-23 16:36:54 +08:00
2019-08-09 10:13:55 +08:00
option(['site_url' => url('/')]);
2019-03-23 16:36:54 +08:00
$admin = new User;
$admin->email = $this->argument('email');
$admin->nickname = $this->argument('nickname');
$admin->score = option('user_initial_score');
$admin->avatar = 0;
$admin->password = app('cipher')->hash($this->argument('password'), config('secure.salt'));
$admin->ip = '127.0.0.1';
$admin->permission = User::SUPER_ADMIN;
$admin->register_at = get_datetime_string();
$admin->last_sign_at = get_datetime_string(time() - 86400);
$admin->verified = true;
$admin->save();
$this->info('Installation completed!');
$this->info('We recommend to modify your "Site URL" option if incorrect.');
}
}