通过 php artisan root:password 重置管理员密码

This commit is contained in:
Edward Yang 2023-02-13 21:08:02 +08:00
parent 90c1f0ed15
commit d25ac50551
5 changed files with 49 additions and 6 deletions

View File

@ -23,10 +23,11 @@ use Beike\Admin\View\Components\Form\Textarea;
use Beike\Admin\View\Components\Header; use Beike\Admin\View\Components\Header;
use Beike\Admin\View\Components\NoData; use Beike\Admin\View\Components\NoData;
use Beike\Admin\View\Components\Sidebar; use Beike\Admin\View\Components\Sidebar;
use Beike\Console\Commands\ChangeRootPassword;
use Beike\Console\Commands\GenerateDatabaseDict; use Beike\Console\Commands\GenerateDatabaseDict;
use Beike\Console\Commands\GenerateSitemap;
use Beike\Console\Commands\MakeRootAdminUser; use Beike\Console\Commands\MakeRootAdminUser;
use Beike\Console\Commands\MigrateFromOpenCart; use Beike\Console\Commands\MigrateFromOpenCart;
use Beike\Console\Commands\Sitemap;
use Beike\Models\AdminUser; use Beike\Models\AdminUser;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
@ -84,10 +85,11 @@ class AdminServiceProvider extends ServiceProvider
{ {
if ($this->app->runningInConsole()) { if ($this->app->runningInConsole()) {
$this->commands([ $this->commands([
ChangeRootPassword::class,
GenerateDatabaseDict::class,
GenerateSitemap::class,
MakeRootAdminUser::class, MakeRootAdminUser::class,
MigrateFromOpenCart::class, MigrateFromOpenCart::class,
GenerateDatabaseDict::class,
Sitemap::class,
]); ]);
} }
} }

View File

@ -0,0 +1,41 @@
<?php
/**
* ChangeRootPassword.php
*
* @copyright 2023 beikeshop.com - All Rights Reserved
* @link https://beikeshop.com
* @author Edward Yang <yangjin@guangda.work>
* @created 2023-02-13 20:56:16
* @modified 2023-02-13 20:56:16
*/
namespace Beike\Console\Commands;
use Beike\Models\AdminUser;
use Illuminate\Console\Command;
class ChangeRootPassword extends Command
{
protected $signature = 'root:password';
protected $description = '修改后台Root账号(第一个管理员)';
/**
* @throws \Throwable
*/
public function handle()
{
$user = AdminUser::query()->first();
$newPassword = $this->ask("请为管理员 {$user->email} 设置新密码:");
if (! $newPassword) {
$this->info('请输入新密码');
return;
}
$user->password = bcrypt($newPassword);
$user->saveOrFail();
$this->info('管理员密码设置成功!');
}
}

View File

@ -5,7 +5,7 @@ namespace Beike\Console\Commands;
use Beike\Services\SitemapService; use Beike\Services\SitemapService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
class Sitemap extends Command class GenerateSitemap extends Command
{ {
/** /**
* The name and signature of the console command. * The name and signature of the console command.

View File

@ -2,6 +2,6 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/test', function (){ Route::get('/test', function () {
echo __FILE__; echo __FILE__;
})->name('test'); })->name('test');