Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
wallet
token
Commits
136adbd7
Commit
136adbd7
authored
Dec 28, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/manage-user' into 'master'
Feature/manage user See merge request
!430
parents
7516e69a
5056fa96
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
8 deletions
+95
-8
UserAuthInterceptor.php
common/behaviors/UserAuthInterceptor.php
+2
-0
Admin.php
common/models/Admin.php
+4
-3
User.php
common/models/User.php
+2
-2
Admin.php
common/modelsgii/Admin.php
+4
-3
UserController.php
wallet/controllers/UserController.php
+83
-0
No files found.
common/behaviors/UserAuthInterceptor.php
View file @
136adbd7
...
...
@@ -34,6 +34,8 @@ class UserAuthInterceptor extends ActionFilter
goto
doEnd
;
}
return
true
;
$group
=
$user
[
"data"
]
->
group
;
$user_id
=
$user
[
"data"
]
->
uid
;
$platform_id
=
$user
[
"data"
]
->
platform_id
;
...
...
common/models/Admin.php
View file @
136adbd7
...
...
@@ -22,10 +22,11 @@ use yii\web\IdentityInterface;
* @property string $update_time
* @property integer $status
* @property integer $platform_id
* @property integer $group
*/
class
Admin
extends
\common\modelsgii\Admin
implements
IdentityInterface
{
const
STATUS_DELETED
=
0
;
const
STATUS_DELETED
=
2
;
const
STATUS_ACTIVE
=
1
;
/**
...
...
@@ -33,7 +34,7 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
*/
public
static
function
findIdentity
(
$uid
)
{
return
static
::
find
()
->
where
([
'uid'
=>
$uid
,
'status'
=>
self
::
STATUS_ACTIVE
])
->
one
();
return
static
::
find
()
->
where
([
'uid'
=>
$uid
])
->
one
();
}
/**
...
...
@@ -44,7 +45,7 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
*/
public
static
function
findByUsername
(
$username
)
{
return
static
::
findOne
([
'username'
=>
$username
,
'status'
=>
self
::
STATUS_ACTIVE
]);
return
static
::
findOne
([
'username'
=>
$username
]);
}
/**
...
...
common/models/User.php
View file @
136adbd7
...
...
@@ -23,8 +23,8 @@ use yii\web\IdentityInterface;
*/
class
User
extends
ActiveRecord
implements
IdentityInterface
{
const
STATUS_DELETED
=
0
;
const
STATUS_ACTIVE
=
1
0
;
const
STATUS_DELETED
=
2
;
const
STATUS_ACTIVE
=
1
;
const
AUTH_SUPER
=
'administrator'
;
...
...
common/modelsgii/Admin.php
View file @
136adbd7
...
...
@@ -19,6 +19,7 @@ use yii\helpers\HtmlPurifier;
* @property string $update_time
* @property integer $status
* @property integer $platform_id
* @property integer $group
*/
class
Admin
extends
\common\core\BaseActiveRecord
{
...
...
@@ -48,7 +49,7 @@ class Admin extends \common\core\BaseActiveRecord
[[
'username'
],
'string'
,
'max'
=>
32
],
[[
'password'
],
'string'
,
'min'
=>
6
,
'max'
=>
60
],
[[
'salt'
],
'string'
,
'max'
=>
32
],
[
'access_token'
,
'safe'
]
[
[
'access_token'
,
'group'
]
,
'safe'
]
];
}
...
...
@@ -68,8 +69,8 @@ class Admin extends \common\core\BaseActiveRecord
'last_login_ip'
=>
'Last Login Ip'
,
'update_time'
=>
'Update Time'
,
'status'
=>
'Status'
,
'platform_id'
=>
'
platform_i
d'
,
'group'
=>
'
g
roup'
'platform_id'
=>
'
PlatformI
d'
,
'group'
=>
'
G
roup'
];
}
}
wallet/controllers/UserController.php
View file @
136adbd7
...
...
@@ -34,6 +34,12 @@ class UserController extends BaseController
$code
=
-
1
;
goto
doEnd
;
}
if
(
Admin
::
STATUS_DELETED
==
$user
->
status
)
{
$msg
=
'用户已停用'
;
$data
=
null
;
$code
=
-
1
;
goto
doEnd
;
}
$token
=
[
'iss'
=>
'https://www.bitfeel.cn'
,
//签发者 可选
'aud'
=>
'https://www.bitfeel.cn'
,
//接收该JWT的一方,可选
...
...
@@ -358,4 +364,80 @@ class UserController extends BaseController
doEnd
:
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'data'
=>
$this
->
data
];
}
public
function
actionAdd
()
{
if
(
!
Yii
::
$app
->
request
->
isPost
)
{
$this
->
msg
=
'请求方式错误'
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$group
=
Yii
::
$app
->
request
->
getGroup
();
if
(
!
in_array
(
$group
,
[
'administrator'
,
'admin'
]))
{
$this
->
code
=
-
1
;
$this
->
msg
=
'当前用户无权操作'
;
goto
doEnd
;
}
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
'administrator'
===
$group
)
{
$platform_id
=
Yii
::
$app
->
request
->
post
(
'platform_id'
,
1
);
}
$token
=
Yii
::
$app
->
request
->
headers
->
get
(
'Token'
);
$user_info
=
Admin
::
verfication
(
$token
);
if
(
0
!=
$user_info
[
'code'
])
{
$this
->
msg
=
$user_info
[
'data'
];
$this
->
code
=
-
1
;
goto
doEnd
;
}
$data
=
Yii
::
$app
->
request
->
post
();
$username
=
Yii
::
$app
->
request
->
post
(
'username'
,
null
);
$password
=
Yii
::
$app
->
request
->
post
(
'password'
,
null
);
if
(
empty
(
$username
))
{
$this
->
code
=
-
1
;
$this
->
msg
=
'用户名不能为空'
;
goto
doEnd
;
}
if
(
empty
(
$password
))
{
$this
->
code
=
-
1
;
$this
->
msg
=
'密码不能为空'
;
goto
doEnd
;
}
if
(
strlen
(
$data
[
'password'
])
<
6
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'密码不能小于6字符'
;
goto
doEnd
;
}
$user
=
Admin
::
findByUsername
(
$username
);
if
(
$user
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'用户名已存在'
;
goto
doEnd
;
}
$params
=
[
'username'
=>
$username
,
'reg_time'
=>
time
(),
'status'
=>
$data
[
'status'
]
??
0
,
'update_time'
=>
0
,
'last_login_time'
=>
0
,
'group'
=>
'general'
,
'platform_id'
=>
$platform_id
,
'reg_ip'
=>
ip2long
(
Yii
::
$app
->
request
->
getUserIP
()),
'last_login_ip'
=>
ip2long
(
'127.0.0.1'
),
];
$model
=
new
Admin
();
#var_dump($model->getAttributes());exit;
$model
->
setAttributes
(
$params
);
$model
->
generateAuthKey
();
$model
->
setPassword
(
$password
);
$model
->
save
();
doEnd
:
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'data'
=>
$this
->
data
];
}
}
\ No newline at end of file
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