fixed bug

This commit is contained in:
yanwenwu 2018-12-09 09:26:58 +08:00
parent 3c3c0471e1
commit 68149ab954
5 changed files with 61 additions and 16 deletions

View File

@ -11,6 +11,8 @@ use app\behavior\LoginRecord;
trait Auth trait Auth
{ {
protected $loginUserKey = 'user';
public function authLogin(Request $request) public function authLogin(Request $request)
{ {
$err = $this->validateLogin($request); $err = $this->validateLogin($request);
@ -27,7 +29,7 @@ trait Auth
$this->error('登录失败'); $this->error('登录失败');
} }
if (password_verify($request->param('password'), $user->password)) { if (password_verify($request->param('password'), $user->password)) {
Session::set('user', $user); Session::set($this->loginUserKey, $user);
# 记住登录 # 记住登录
$this->LoginRemember($user, $request); $this->LoginRemember($user, $request);
# 登录记录 # 登录记录
@ -46,7 +48,7 @@ trait Auth
public function rememberLogin() public function rememberLogin()
{ {
// 如果记住登录 // 如果记住登录
if (!Session::get('user') && Cookie::get('remember_token') && $this->checkRememberToken()) { if (!Session::get($this->loginUserKey) && Cookie::get('remember_token') && $this->checkRememberToken()) {
return true; return true;
} }
@ -59,11 +61,18 @@ trait Auth
*/ */
public function authLogout() public function authLogout()
{ {
$user = Session::get('user'); $user = Session::get($this->loginUserKey);
$this->deleteToken($user);
Session::delete($this->loginUserKey);
}
protected function deleteToken($user)
{
if ($user->remember_token) {
$user->remember_token = null; $user->remember_token = null;
$user->save(); $user->save();
Cookie::delete('remember_token'); Cookie::delete('remember_token');
Session::delete('user'); }
} }
/** /**
* 验证 * 验证

18
composer.lock generated
View File

@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v5.1.29", "version": "v5.1.30",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/framework.git", "url": "https://github.com/top-think/framework.git",
"reference": "f1d8ee3a91e8f504507edb5dcc49c50c47b4500f" "reference": "4fefa5ed2f9dc8a15fcf7bb271d0d918fb48dacc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/f1d8ee3a91e8f504507edb5dcc49c50c47b4500f", "url": "https://api.github.com/repos/top-think/framework/zipball/4fefa5ed2f9dc8a15fcf7bb271d0d918fb48dacc",
"reference": "f1d8ee3a91e8f504507edb5dcc49c50c47b4500f", "reference": "4fefa5ed2f9dc8a15fcf7bb271d0d918fb48dacc",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -61,7 +61,7 @@
"orm", "orm",
"thinkphp" "thinkphp"
], ],
"time": "2018-11-11T01:17:33+00:00" "time": "2018-11-30T07:46:23+00:00"
}, },
{ {
"name": "topthink/think-captcha", "name": "topthink/think-captcha",
@ -206,12 +206,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/yanwenwu/thinkphp-permission.git", "url": "https://github.com/yanwenwu/thinkphp-permission.git",
"reference": "670caf6a98a476e769fb24002aeb5feb5f2a6e69" "reference": "c9341e22c73e30c963a3aebc6da842af7ebc3f26"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/yanwenwu/thinkphp-permission/zipball/670caf6a98a476e769fb24002aeb5feb5f2a6e69", "url": "https://api.github.com/repos/yanwenwu/thinkphp-permission/zipball/c9341e22c73e30c963a3aebc6da842af7ebc3f26",
"reference": "670caf6a98a476e769fb24002aeb5feb5f2a6e69", "reference": "c9341e22c73e30c963a3aebc6da842af7ebc3f26",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -243,7 +243,7 @@
} }
], ],
"description": "rbac", "description": "rbac",
"time": "2018-10-10T13:12:58+00:00" "time": "2018-11-30T02:01:37+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

View File

@ -24,6 +24,8 @@ class Permissions extends Seeder
'controller' => '', 'controller' => '',
'action' => '', 'action' => '',
'is_show' => 1, 'is_show' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -35,6 +37,8 @@ class Permissions extends Seeder
'controller' => 'user', 'controller' => 'user',
'action' => 'index', 'action' => 'index',
'is_show' => 1, 'is_show' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -46,6 +50,8 @@ class Permissions extends Seeder
'controller' => 'role', 'controller' => 'role',
'action' => 'index', 'action' => 'index',
'is_show' => 1, 'is_show' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -57,6 +63,8 @@ class Permissions extends Seeder
'controller' => 'permission', 'controller' => 'permission',
'action' => 'index', 'action' => 'index',
'is_show' => 1, 'is_show' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -68,6 +76,8 @@ class Permissions extends Seeder
'controller' => 'user', 'controller' => 'user',
'action' => 'create', 'action' => 'create',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -79,6 +89,8 @@ class Permissions extends Seeder
'controller' => 'user', 'controller' => 'user',
'action' => 'edit', 'action' => 'edit',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -90,6 +102,8 @@ class Permissions extends Seeder
'controller' => 'user', 'controller' => 'user',
'action' => 'delete', 'action' => 'delete',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -101,6 +115,8 @@ class Permissions extends Seeder
'controller' => 'role', 'controller' => 'role',
'action' => 'create', 'action' => 'create',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -112,6 +128,8 @@ class Permissions extends Seeder
'controller' => 'role', 'controller' => 'role',
'action' => 'edit', 'action' => 'edit',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -123,6 +141,8 @@ class Permissions extends Seeder
'controller' => 'role', 'controller' => 'role',
'action' => 'delete', 'action' => 'delete',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -134,6 +154,8 @@ class Permissions extends Seeder
'controller' => 'role', 'controller' => 'role',
'action' => 'getPermissionsOfRole', 'action' => 'getPermissionsOfRole',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -145,6 +167,8 @@ class Permissions extends Seeder
'controller' => 'role', 'controller' => 'role',
'action' => 'givePermissions', 'action' => 'givePermissions',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -156,6 +180,8 @@ class Permissions extends Seeder
'controller' => 'user', 'controller' => 'user',
'action' => 'giveRoles', 'action' => 'giveRoles',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -167,6 +193,8 @@ class Permissions extends Seeder
'controller' => 'permission', 'controller' => 'permission',
'action' => 'create', 'action' => 'create',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -178,6 +206,8 @@ class Permissions extends Seeder
'controller' => 'permission', 'controller' => 'permission',
'action' => 'edit', 'action' => 'edit',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
[ [
@ -189,6 +219,8 @@ class Permissions extends Seeder
'controller' => 'permission', 'controller' => 'permission',
'action' => 'delete', 'action' => 'delete',
'is_show' => 2, 'is_show' => 2,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
], ],
]; ];

View File

@ -17,6 +17,8 @@ class Roles extends Seeder
$data = [ $data = [
'name' => '超级管理员', 'name' => '超级管理员',
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]; ];
$this->table(config('permissions.table.role'))->insert($data)->save(); $this->table(config('permissions.table.role'))->insert($data)->save();

View File

@ -18,6 +18,8 @@ class Users extends Seeder
'name' => 'admin', 'name' => 'admin',
'email' => 'admin@gmail.com', 'email' => 'admin@gmail.com',
'password' => password_hash('admin', PASSWORD_DEFAULT), 'password' => password_hash('admin', PASSWORD_DEFAULT),
'created_at' => date('Y-m-d H:i:s'),
'login_at' => date('Y-m-d H:i:s'),
]; ];
$this->table('users')->insert([$data])->save(); $this->table('users')->insert([$data])->save();