Skip to content

Commit 74c111f

Browse files
committed
5.2.1
1 parent 903d492 commit 74c111f

File tree

5 files changed

+64
-106
lines changed

5 files changed

+64
-106
lines changed

src/auth/Api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Api
3939
* 不需要鉴权方法
4040
*/
4141
protected $noAuth = [];
42-
42+
4343
protected $member_id = '';
4444

4545
protected $type ='simple';
@@ -50,7 +50,7 @@ class Api
5050
*/
5151
public function __construct(App $app)
5252
{
53-
$this->type = Config::get('api.type','simple');
53+
$this->type = Config::get('api.type')?:"simple";
5454
$this->request = Request::instance();
5555
$this->request->filter('trim,strip_tags,htmlspecialchars');
5656
$this->group = $this->request->param('group')?$this->request->param('group'):'api';
@@ -81,4 +81,4 @@ public function _empty()
8181
{
8282
$this->error('empty method!');
8383
}
84-
}
84+
}

src/auth/Send.php

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ trait Send
4444

4545
/**
4646
* redis 对象
47-
* @var
47+
* @var
4848
*/
4949
public $redis ;
5050
/**
5151
* 客户端对象
52-
* @var
52+
* @var
5353
*/
5454
public $client ;
5555

@@ -69,10 +69,10 @@ trait Send
6969
protected $appsecret = '';
7070
/**
7171
* JWT key
72-
* @var string
72+
* @var string
7373
*/
7474
public $key = '';
75-
75+
7676
public $group = 'api';
7777

7878
/**
@@ -198,6 +198,61 @@ public function match($arr = [])
198198
return false;
199199
}
200200

201+
/**
202+
* token
203+
* @param $memberInfo
204+
* @param $expires
205+
* @return string
206+
*/
207+
protected function buildAccessToken($memberInfo,$expires)
208+
{
209+
$time = time(); //签发时间
210+
$expire = $time + $expires; //过期时间
211+
$scopes = 'role_access';
212+
if($expires==$this->refreshExpires) $scopes = 'role_refresh';
213+
$token = array(
214+
"member_id" => $memberInfo['member_id'],
215+
'appid'=>$this->appid,
216+
'appsecret'=>$this->appsecret,
217+
"iss" => "funadmin.com",//签发组织
218+
"aud" => "funadmin", //签发作者
219+
"scopes" => $scopes, //刷新
220+
"iat" => $time,
221+
"nbf" => $time,
222+
"exp" => $expire, //过期时间时间戳
223+
);
224+
return JWT::encode($token, $this->key, 'HS256');
225+
}
226+
227+
/**
228+
* @param $membername
229+
* @param $password
230+
* @return array|mixed|void
231+
* @throws \think\db\exception\DataNotFoundException
232+
* @throws \think\db\exception\DbException
233+
* @throws \think\db\exception\ModelNotFoundException
234+
*/
235+
protected function getMember($membername, $password)
236+
{
237+
$member = Db::name($this->tableName)
238+
->where('status',1)
239+
->where('username', $membername)
240+
->whereOr('mobile', $membername)
241+
->whereOr('email', $membername)
242+
->field('id as member_id,password')
243+
->limit(1)
244+
->find();
245+
if ($member) {
246+
if (password_verify($password, $member['password'])) {
247+
unset($member['password']);
248+
return $member;
249+
} else {
250+
$this->error(lang('Password is not right'), [], 401);
251+
}
252+
} else {
253+
$this->error(lang('Account is not exist'), [], 401);
254+
}
255+
}
201256

202257
}
203258

src/auth/SimpleToken.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
namespace fun\auth;
1515

1616
use app\common\service\PredisService;
17-
use Firebase\JWT\Key;
1817
use think\facade\Config;
1918
use think\facade\Request;
2019
use fun\auth\Send;
2120
use think\facade\Db;
2221
use think\Lang;
23-
use Firebase\JWT\JWT;
2422
/**
2523
* 生成token
2624
*/
@@ -96,51 +94,4 @@ public function refresh()
9694
$accessToken = $this->buildAccessToken($memberInfo,$this->expires);
9795
$this->success(lang('success'), ['access_token'=>$accessToken]);
9896
}
99-
100-
/**
101-
* 生成AccessToken
102-
* @return string
103-
*/
104-
protected function buildAccessToken($memberInfo,$expires)
105-
{
106-
$time = time(); //签发时间
107-
$expire = $time + $expires; //过期时间
108-
$scopes = 'role_access';
109-
if($expires==$this->refreshExpires) $scopes = 'role_refresh';
110-
$token = array(
111-
"member_id" => $memberInfo['member_id'],
112-
'appid'=>$this->appid,
113-
'appsecret'=>$this->appsecret,
114-
"iss" => "https://www.funadmin.com",//签发组织
115-
"aud" => "https://www.funadmin.com", //签发作者
116-
"scopes" => $scopes, //刷新
117-
"iat" => $time,
118-
"nbf" => $time,
119-
"exp" => $expire, //过期时间时间戳
120-
);
121-
return JWT::encode($token, $this->key, 'HS256');
122-
}
123-
124-
125-
protected function getMember($membername, $password)
126-
{
127-
$member = Db::name($this->tableName)
128-
->where('status',1)
129-
->where('username', $membername)
130-
->whereOr('mobile', $membername)
131-
->whereOr('email', $membername)
132-
->field('id as member_id,password')
133-
// ->cache($this->appid.$membername,3600)
134-
->find();
135-
if ($member) {
136-
if (password_verify($password, $member['password'])) {
137-
unset($member['password']);
138-
return $member;
139-
} else {
140-
$this->error(lang('Password is not right'), [], 401);
141-
}
142-
} else {
143-
$this->error(lang('Account is not exist'), [], 401);
144-
}
145-
}
14697
}

src/auth/Token.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use fun\auth\Send;
2020
use think\facade\Db;
2121
use think\Lang;
22-
use Firebase\JWT\JWT;
2322
/**
2423
* 生成token
2524
*/
@@ -206,30 +205,6 @@ public function checkParams($params = [])
206205
}
207206
}
208207

209-
/**
210-
* 生成AccessToken
211-
* @return string
212-
*/
213-
protected function buildAccessToken($memberInfo,$expires)
214-
{
215-
$time = time(); //签发时间
216-
$expire = $time + $expires; //过期时间
217-
$scopes = 'role_access';
218-
if($expires==$this->refreshExpires) $scopes = 'role_refresh';
219-
$token = array(
220-
"member_id" => $memberInfo['member_id'],
221-
'appid'=>$this->appid,
222-
'appsecret'=>$this->appsecret,
223-
"iss" => "https://www.funadmin.com",//签发组织
224-
"aud" => "https://www.funadmin.com", //签发作者
225-
"scopes" => $scopes, //刷新
226-
"iat" => $time,
227-
"nbf" => $time,
228-
"exp" => $expire, //过期时间时间戳
229-
);
230-
return JWT::encode($token, $this->key, 'HS256');
231-
}
232-
233208
/**
234209
* 获取刷新用的token检测是否还有效
235210
*/
@@ -279,29 +254,6 @@ protected function saveToken($accessTokenInfo)
279254
return true;
280255
}
281256

282-
protected function getMember($membername, $password)
283-
{
284-
$member = Db::name($this->tableName)
285-
->where('status',1)
286-
->where('username', $membername)
287-
->whereOr('mobile', $membername)
288-
->whereOr('email', $membername)
289-
->field('id as member_id,password')
290-
->limit(1)
291-
->find();
292-
if ($member) {
293-
if (password_verify($password, $member['password'])) {
294-
unset($member['password']);
295-
return $member;
296-
} else {
297-
$this->error(lang('Password is not right'), [], 401);
298-
}
299-
} else {
300-
$this->error(lang('Account is not exist'), [], 401);
301-
}
302-
}
303-
304-
305257
/**
306258
* 生成签名
307259
* 字符开头的变量不参与签名

src/curd/service/CurdService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class CurdService
2727
'fields' => [],//显示的字段
2828
'ignoreFields' => ['create_time', 'status', 'update_time', 'delete_time'],//忽略字段
2929
'tagsSuffix' => ['tags', 'tag'],//识别为tag类型
30-
'urlSuffix' => ['url', 'urls'],//识别为tag类型
30+
'urlSuffix' => ['url', 'urls'],//识别为url类型
3131
'fileSuffix' => ['file', 'files', 'path', 'paths'],//识别为文件字段
3232
'priSuffix' => ['_id', '_ids'],//识别为别的表的主键
33-
'sortSuffix' => ['sort'],//排序
33+
'sortSuffix' => ['sort','orderby','weight'],//排序
3434
'imageSuffix' => ['image', 'images', 'thumb', 'thumbs', 'avatar', 'avatars','picture', 'pictures',''],//识别为图片字段
3535
'editorSuffix' => ['editor', 'content', 'detail', 'details', 'description'],//识别为编辑器字段
3636
'iconSuffix' => ['icon'],//识别为图标字段

0 commit comments

Comments
 (0)