fixed:修复表信息获取
This commit is contained in:
parent
8a901e89cb
commit
a86387a47e
@ -1,110 +0,0 @@
|
||||
<?php
|
||||
namespace catchAdmin\Auth;
|
||||
|
||||
use catchAdmin\permissions\model\Permissions;
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catcher\exceptions\LoginFailedException;
|
||||
use thans\jwt\facade\JWTAuth;
|
||||
use think\facade\Session;
|
||||
|
||||
class Auth
|
||||
{
|
||||
protected const USER_ID = 'catch_uid';
|
||||
/**
|
||||
* 登陆
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws LoginFailedException
|
||||
*/
|
||||
public static function login($params)
|
||||
{
|
||||
$user = Users::where('email', $params['email'])->find();
|
||||
|
||||
if (!$user) {
|
||||
throw new LoginFailedException('登陆失败, 请检查用户名和密码');
|
||||
}
|
||||
|
||||
if (!password_verify($params['password'], $user->password)) {
|
||||
throw new LoginFailedException('登陆失败, 请检查用户名和密码');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Session::set(self::getLoginUserKey(), $user);
|
||||
|
||||
return JWTAuth::builder([self::USER_ID => $user->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登陆
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @return bool
|
||||
*/
|
||||
public static function logout(): bool
|
||||
{
|
||||
Session::delete(self::getLoginUserKey());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月15日
|
||||
* @return mixed
|
||||
*/
|
||||
public static function user()
|
||||
{
|
||||
return Users::where('id', JWTAuth::auth()[self::USER_ID])
|
||||
->field(['id', 'username', 'status'])->find();
|
||||
}
|
||||
|
||||
public static function getUserInfo()
|
||||
{
|
||||
$user = self::user();
|
||||
|
||||
$roles = $user->getRoles();
|
||||
|
||||
$user->permissions = Permissions::whereIn('id', $user->getPermissionsBy())
|
||||
->field(['permission_name as title', 'route', 'icon'])
|
||||
->select();
|
||||
|
||||
$user->roles = $roles;
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月15日
|
||||
* @return string
|
||||
*/
|
||||
protected static function getLoginUserKey(): string
|
||||
{
|
||||
// return md5(self::USER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月15日
|
||||
* @param $mark
|
||||
* @param $module
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasPermissions($mark, $module): bool
|
||||
{
|
||||
$user = self::user();
|
||||
|
||||
$permissionIds = $user->getPermissionsBy($user->id);
|
||||
|
||||
$permissionId = Permissions::where('module', $module)
|
||||
->where('permission_mark', $mark)->value('id');
|
||||
|
||||
return in_array($permissionId, $permissionIds);
|
||||
}
|
||||
}
|
@ -62,13 +62,7 @@ class DataDictionary extends CatchController
|
||||
*/
|
||||
public function view($table): \think\response\Json
|
||||
{
|
||||
$fields = Db::query(' ' . $table);
|
||||
|
||||
array_walk($fields, function (&$item){
|
||||
$item = array_change_key_case($item);
|
||||
});
|
||||
|
||||
return CatchResponse::success($fields);
|
||||
return CatchResponse::success(array_values(Db::getFields($table)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user