初始化仓库
This commit is contained in:
36
console/controllers/AdminController.php
Normal file
36
console/controllers/AdminController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace console\controllers;
|
||||
|
||||
use admin\models\Admin;
|
||||
use common\helpers\StringHelper;
|
||||
use common\models\admin\Member;
|
||||
use Yii;
|
||||
use yii\console\Controller;
|
||||
use yii\helpers\Console;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function actionCreate()
|
||||
{
|
||||
$count = (int)Admin::find()->where(['role' => 0])->count();
|
||||
if ($count===0) {
|
||||
$model = new Admin();
|
||||
$model->username = StringHelper::random(6);
|
||||
$model->generateAuthKey();
|
||||
$password_hash = StringHelper::random(10);
|
||||
$model->setPassword($password_hash);
|
||||
if ($model->save()) {
|
||||
Console::output('username; ' . $model->username);
|
||||
Console::output('password; ' . $password_hash);
|
||||
exit();
|
||||
}
|
||||
|
||||
Console::stdout('Password initialization failed');
|
||||
exit();
|
||||
}
|
||||
|
||||
Console::stdout('已经有超管账号');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user