Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
newShopBack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
newshop
newShopBack
Commits
770e09ae
Commit
770e09ae
authored
Nov 15, 2019
by
郭勇志
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式化rediskey方法
parent
c849bc30
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
16 deletions
+20
-16
Func.php
backend/helpers/Func.php
+12
-0
BaseModel.php
backend/models/v1/BaseModel.php
+0
-12
LoginForm.php
backend/models/v1/rbacuser/LoginForm.php
+4
-2
ShopRbacUser.php
backend/models/v1/rbacuser/ShopRbacUser.php
+4
-2
No files found.
backend/helpers/Func.php
View file @
770e09ae
...
...
@@ -11,4 +11,16 @@ class Func
}
return
sprintf
(
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X'
,
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
),
mt_rand
(
16384
,
20479
),
mt_rand
(
32768
,
49151
),
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
));
}
/**
* 格式化redis key
* @return string
*/
public
function
formatKey
(
$key
)
{
$preFix
=
REDIS_PREFIX
;
if
(
substr
(
$key
,
0
,
strlen
(
$preFix
))
==
$preFix
)
{
return
$key
;
}
return
$preFix
.
$key
;
}
}
backend/models/v1/BaseModel.php
View file @
770e09ae
...
...
@@ -28,16 +28,4 @@ class BaseModel extends ActiveRecord
}
return
Yii
::
$app
->
$db
;
}
/**
* 格式化redis key
* @return string
*/
public
function
formatKey
(
$key
)
{
$preFix
=
REDIS_PREFIX
;
if
(
substr
(
$key
,
0
,
strlen
(
$preFix
))
==
$preFix
)
{
return
$key
;
}
return
$preFix
.
$key
;
}
}
\ No newline at end of file
backend/models/v1/rbacuser/LoginForm.php
View file @
770e09ae
...
...
@@ -5,6 +5,7 @@ use Yii;
use
app\models\v1\rbacuser\ShopRbacUser
;
use
app\models\v1\BaseModel
;
use
yii\web\HttpException
;
use
backend\helpers\Func
;
/**
* Login form
*/
...
...
@@ -56,9 +57,10 @@ class LoginForm extends BaseModel
if
(
$this
->
validate
())
{
$accessToken
=
$this
->
_shopRbacUser
->
generateAccessToken
();
// 生成access_token=>array(用户GUID,ORG_GUID)保存到redis
$func
=
new
Func
;
$redis
=
Yii
::
$app
->
redis
;
$rtnSet
=
$redis
->
set
(
$
this
->
formatKey
(
$accessToken
),
json_encode
(
array
(
'USER_GUID'
=>
$this
->
_shopRbacUser
->
GUID
,
'ORG_GUID'
=>
$this
->
_shopRbacUser
->
ORG_GUID
)));
$rtnExpire
=
$redis
->
expire
(
$
this
->
formatKey
(
$accessToken
),
10800
);
$rtnSet
=
$redis
->
set
(
$
func
->
formatKey
(
$accessToken
),
json_encode
(
array
(
'USER_GUID'
=>
$this
->
_shopRbacUser
->
GUID
,
'ORG_GUID'
=>
$this
->
_shopRbacUser
->
ORG_GUID
)));
$rtnExpire
=
$redis
->
expire
(
$
func
->
formatKey
(
$accessToken
),
10800
);
if
(
$rtnSet
&&
$rtnExpire
)
{
return
$accessToken
;
}
...
...
backend/models/v1/rbacuser/ShopRbacUser.php
View file @
770e09ae
...
...
@@ -5,7 +5,8 @@ namespace app\models\v1\rbacuser;
use
Yii
;
use
yii\web\IdentityInterface
;
use
app\models\v1\BaseModel
;
use
yii\web\HttpException
;
use
yii\web\HttpException
;
use
backend\helpers\Func
;
/**
* This is the model class for table "shop_rbac_user".
*
...
...
@@ -135,7 +136,8 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
// 取得reids中用户信息
$redis
=
Yii
::
$app
->
redis
;
$model
=
new
ShopRbacUser
;
$rtnGet
=
$redis
->
get
(
$model
->
formatKey
(
$token
));
$func
=
new
Func
;
$rtnGet
=
$redis
->
get
(
$func
->
formatKey
(
$token
));
if
(
$rtnGet
)
{
$userInfo
=
json_decode
(
$rtnGet
,
true
);
$db
=
DB_PREFIX
.
$userInfo
[
'ORG_GUID'
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment