backstage seeds upload
This commit is contained in:
parent
0e0492978c
commit
a38ec53d1d
@ -36,7 +36,7 @@ class User extends Base
|
|||||||
if ($err = $validate->getErrors($data)) {
|
if ($err = $validate->getErrors($data)) {
|
||||||
$this->error($err);
|
$this->error($err);
|
||||||
}
|
}
|
||||||
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
|
$data['password'] = generatePassword($data['password']);
|
||||||
if ($userId = $userModel->store($data)) {
|
if ($userId = $userModel->store($data)) {
|
||||||
// 分配角色
|
// 分配角色
|
||||||
$this->giveRoles($userModel, $userId, $data);
|
$this->giveRoles($userModel, $userId, $data);
|
||||||
@ -63,7 +63,7 @@ class User extends Base
|
|||||||
$this->error($err);
|
$this->error($err);
|
||||||
}
|
}
|
||||||
$this->giveRoles($userModel, $data['id'], $data);
|
$this->giveRoles($userModel, $data['id'], $data);
|
||||||
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
|
$data['password'] = generatePassword($data['password']);
|
||||||
$userModel->updateBy($data['id'], $data) ? $this->success('修改成功', url('user/index')) : $this->error('修改失败');
|
$userModel->updateBy($data['id'], $data) ? $this->success('修改成功', url('user/index')) : $this->error('修改失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,3 +56,12 @@ if (!function_exists('searchButton')) {
|
|||||||
return sprintf('<button class="btn btn-white" type="submit"><i class="fa fa-search"></i> %s</button>', $name);
|
return sprintf('<button class="btn btn-white" type="submit"><i class="fa fa-search"></i> %s</button>', $name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成密码
|
||||||
|
*/
|
||||||
|
if (!function_exists('generatePassword')) {
|
||||||
|
function generatePassword(string $password, int $algo = PASSWORD_DEFAULT) {
|
||||||
|
return password_hash($password, $algo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ class Users extends Migrator
|
|||||||
->addColumn('login_ip', 'string',['limit' => 50, 'default'=>'','comment'=>'登录IP'])
|
->addColumn('login_ip', 'string',['limit' => 50, 'default'=>'','comment'=>'登录IP'])
|
||||||
->addColumn('created_at', 'timestamp', [ 'comment' => '更新时间'])
|
->addColumn('created_at', 'timestamp', [ 'comment' => '更新时间'])
|
||||||
->addColumn('login_at', 'timestamp', [ 'comment' => '最近登录时间'])
|
->addColumn('login_at', 'timestamp', [ 'comment' => '最近登录时间'])
|
||||||
->addIndex(['name'], ['unique' => true])
|
->addIndex(['name', 'email'], ['unique' => true])
|
||||||
->create();
|
->create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
200
database/seeds/Permissions.php
Normal file
200
database/seeds/Permissions.php
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Seeder;
|
||||||
|
|
||||||
|
class Permissions extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/seeding.html
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'name' => '权限管理',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 0,
|
||||||
|
'module' => '',
|
||||||
|
'controller' => '',
|
||||||
|
'action' => '',
|
||||||
|
'is_show' => 1,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 2,
|
||||||
|
'name' => '用户管理',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 1,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'user',
|
||||||
|
'action' => 'index',
|
||||||
|
'is_show' => 1,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'name' => '角色管理',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 1,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'role',
|
||||||
|
'action' => 'index',
|
||||||
|
'is_show' => 1,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 4,
|
||||||
|
'name' => '菜单管理',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 1,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'permission',
|
||||||
|
'action' => 'index',
|
||||||
|
'is_show' => 1,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 5,
|
||||||
|
'name' => '创建用户',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 2,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'user',
|
||||||
|
'action' => 'create',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 6,
|
||||||
|
'name' => '编辑用户',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 2,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'user',
|
||||||
|
'action' => 'edit',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 7,
|
||||||
|
'name' => '删除用户',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 2,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'user',
|
||||||
|
'action' => 'delete',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 8,
|
||||||
|
'name' => '创建角色',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 3,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'role',
|
||||||
|
'action' => 'create',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 9,
|
||||||
|
'name' => '编辑角色',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 3,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'role',
|
||||||
|
'action' => 'edit',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 10,
|
||||||
|
'name' => '删除角色',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 3,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'role',
|
||||||
|
'action' => 'delete',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 11,
|
||||||
|
'name' => '获取角色权限',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 3,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'role',
|
||||||
|
'action' => 'getPermissionsOfRole',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 12,
|
||||||
|
'name' => '分配权限',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 3,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'role',
|
||||||
|
'action' => 'givePermissions',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 13,
|
||||||
|
'name' => '分配角色',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 2,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'user',
|
||||||
|
'action' => 'giveRoles',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 14,
|
||||||
|
'name' => '创建菜单',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 4,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'permission',
|
||||||
|
'action' => 'create',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 15,
|
||||||
|
'name' => '编辑菜单',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 4,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'permission',
|
||||||
|
'action' => 'edit',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'id' => 16,
|
||||||
|
'name' => '删除菜单',
|
||||||
|
'icon' => '',
|
||||||
|
'pid' => 4,
|
||||||
|
'module' => 'admin',
|
||||||
|
'controller' => 'permission',
|
||||||
|
'action' => 'delete',
|
||||||
|
'is_show' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->table(config('permissions.table.permission'))->insert($data)->save();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
28
database/seeds/RoleHasPermissions.php
Normal file
28
database/seeds/RoleHasPermissions.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Seeder;
|
||||||
|
|
||||||
|
class RoleHasPermissions extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/seeding.html
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$p = \think\permissions\facade\Permissions::all();
|
||||||
|
$data = [];
|
||||||
|
foreach ($p as $v) {
|
||||||
|
$data[] = [
|
||||||
|
'role_id' => 1,
|
||||||
|
'permission_id' => $v->id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->table(config('permissions.table.role_has_permissions'))->insert($data)->save();
|
||||||
|
}
|
||||||
|
}
|
24
database/seeds/Roles.php
Normal file
24
database/seeds/Roles.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Seeder;
|
||||||
|
|
||||||
|
class Roles extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/seeding.html
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => '超级管理员',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->table(config('permissions.table.role'))->insert($data)->save();
|
||||||
|
}
|
||||||
|
}
|
24
database/seeds/UserHasRoles.php
Normal file
24
database/seeds/UserHasRoles.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Seeder;
|
||||||
|
|
||||||
|
class UserHasRoles extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/seeding.html
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'uid' => 1,
|
||||||
|
'role_id' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->table(config('permissions.table.user_has_roles'))->insert($data)->save();
|
||||||
|
}
|
||||||
|
}
|
25
database/seeds/Users.php
Normal file
25
database/seeds/Users.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Seeder;
|
||||||
|
|
||||||
|
class Users extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/seeding.html
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'name' => 'admin',
|
||||||
|
'email' => 'admin@gmail.com',
|
||||||
|
'password' => password_hash('admin', PASSWORD_DEFAULT),
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->table('users')->insert([$data])->save();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user