| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Console\Commands\Init;
- use App\Repositories\ManagerRepository;
- use Illuminate\Console\Command;
- use Otp\GoogleAuthenticator;
- class CreateSuperManager extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'init:create_super_manager';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '创建一个超管';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- if (app()->environment() != 'local') {
- $this->error('仅允许开发环境');
- return false;
- }
- /**
- * @var ManagerRepository $managerRepo
- */
- $managerRepo = app(ManagerRepository::class);
- $username = strtolower('adminboss');
- $nick = '超管admin';
- $passwordTxt = 'qwe123456';
- $email = strtolower('adminboss@test.com');
- $salt = 'cTYcEH';
- $password = $managerRepo->generatePassword($passwordTxt, $salt);
- $roleId = 1;
- $roleName = '超管';
- $otpSecret = GoogleAuthenticator::generateRandom();
- $userInfo = [
- 'username' => $username,
- 'nick' => $nick,
- 'role_id' => $roleId,
- 'role_name' => $roleName,
- 'password' => $password,
- 'salt' => $salt,
- 'email' => $email,
- 'otp_secret' => $otpSecret,
- ];
- if ($managerRepo->isExistsUsername($username)) {
- $this->error('用户名已经存在');
- return false;
- }
- $result = $managerRepo->create($userInfo);
- if (!$result) {
- $this->error('创建失败');
- return false;
- } else {
- $this->info('创建超管成功,用户名:'. $username);
- return true;
- }
- }
- }
|