add:新增用户token字段
This commit is contained in:
parent
85f4fc0df8
commit
5f49a22a5e
@ -29,7 +29,7 @@ class Index extends CatchController
|
|||||||
|
|
||||||
$user = $auth->user();
|
$user = $auth->user();
|
||||||
|
|
||||||
$this->afterLoginSuccess($user);
|
$this->afterLoginSuccess($user, $token);
|
||||||
// 登录事件
|
// 登录事件
|
||||||
$this->loginEvent($user->username);
|
$this->loginEvent($user->username);
|
||||||
|
|
||||||
@ -70,12 +70,16 @@ class Index extends CatchController
|
|||||||
*
|
*
|
||||||
* @time 2020年09月09日
|
* @time 2020年09月09日
|
||||||
* @param $user
|
* @param $user
|
||||||
|
* @param $token
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function afterLoginSuccess($user)
|
protected function afterLoginSuccess($user, $token)
|
||||||
{
|
{
|
||||||
$user->last_login_ip = request()->ip();
|
$user->last_login_ip = request()->ip();
|
||||||
$user->last_login_time = time();
|
$user->last_login_time = time();
|
||||||
|
if ($user->hasField('remember_token')) {
|
||||||
|
$user->remember_token = $token;
|
||||||
|
}
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
use think\migration\Migrator;
|
||||||
|
use think\migration\db\Column;
|
||||||
|
|
||||||
|
class AddUserRememberToken extends Migrator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Change Method.
|
||||||
|
*
|
||||||
|
* Write your reversible migrations using this method.
|
||||||
|
*
|
||||||
|
* More information on writing migrations is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||||
|
*
|
||||||
|
* The following commands can be used in this method and Phinx will
|
||||||
|
* automatically reverse them when rolling back:
|
||||||
|
*
|
||||||
|
* createTable
|
||||||
|
* renameTable
|
||||||
|
* addColumn
|
||||||
|
* renameColumn
|
||||||
|
* addIndex
|
||||||
|
* addForeignKey
|
||||||
|
*
|
||||||
|
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||||
|
* with the Table class.
|
||||||
|
*/
|
||||||
|
public function change()
|
||||||
|
{
|
||||||
|
if ($this->hasTable('users')) {
|
||||||
|
$table = $this->table('users');
|
||||||
|
|
||||||
|
$table->addColumn('remember_token', 'string', [
|
||||||
|
'limit' => 512,
|
||||||
|
'default' => '',
|
||||||
|
'comment' => '用户token',
|
||||||
|
'after' => 'avatar'])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ class Users extends CatchModel
|
|||||||
'password', // 用户密码
|
'password', // 用户密码
|
||||||
'email', // 邮箱 登录
|
'email', // 邮箱 登录
|
||||||
'avatar', // 头像
|
'avatar', // 头像
|
||||||
|
'remember_token',
|
||||||
'creator_id', // 创建者ID
|
'creator_id', // 创建者ID
|
||||||
'department_id', // 部门ID
|
'department_id', // 部门ID
|
||||||
'status', // 用户状态 1 正常 2 禁用
|
'status', // 用户状态 1 正常 2 禁用
|
||||||
@ -28,7 +29,6 @@ class Users extends CatchModel
|
|||||||
'created_at', // 创建时间
|
'created_at', // 创建时间
|
||||||
'updated_at', // 更新时间
|
'updated_at', // 更新时间
|
||||||
'deleted_at', // 删除状态,0未删除 >0 已删除
|
'deleted_at', // 删除状态,0未删除 >0 已删除
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,4 +33,16 @@ abstract class CatchModel extends \think\Model
|
|||||||
public const ENABLE = 1;
|
public const ENABLE = 1;
|
||||||
// 禁用
|
// 禁用
|
||||||
public const DISABLE = 2;
|
public const DISABLE = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有 field
|
||||||
|
*
|
||||||
|
* @time 2020年11月23日
|
||||||
|
* @param string $field
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasField(string $field)
|
||||||
|
{
|
||||||
|
return property_exists($this, 'field') ? in_array($field, $this->field) : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user