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
8d008f67
Commit
8d008f67
authored
Sep 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
465ce1ff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
25 deletions
+13
-25
AdminController.php
backend/controllers/AdminController.php
+12
-24
Admin.php
common/modelsgii/Admin.php
+1
-1
No files found.
backend/controllers/AdminController.php
View file @
8d008f67
...
...
@@ -4,7 +4,6 @@ namespace backend\controllers;
use
common\models\Admin
;
use
common\models\search\AdminSearch
;
use
common\core\Exception
;
use
Yii
;
/**
...
...
@@ -62,7 +61,8 @@ class AdminController extends BaseController
$model
->
generateAuthKey
();
$model
->
setPassword
(
$data
[
'password'
]);
$model
->
group
=
$role
;
$model
->
group
=
$role
;
$model
->
platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
/* 保存用户数据到数据库 */
if
(
$model
->
save
())
{
$auth
=
Yii
::
$app
->
authManager
;
...
...
@@ -76,7 +76,7 @@ class AdminController extends BaseController
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
,
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
)
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
)
,
]);
}
...
...
@@ -123,41 +123,29 @@ class AdminController extends BaseController
public
function
actionEdit
()
{
$model
=
new
Admin
(
);
$model
=
Admin
::
findOne
(
Yii
::
$app
->
request
->
get
(
'uid'
)
);
if
(
Yii
::
$app
->
request
->
isPost
)
{
/* 表单验证 */
$data
=
Yii
::
$app
->
request
->
post
(
'Admin'
);
$data
[
'reg_time'
]
=
time
();
$data
[
'reg_ip'
]
=
ip2long
(
Yii
::
$app
->
request
->
getUserIP
());
$data
[
'last_login_time'
]
=
0
;
$data
[
'last_login_ip'
]
=
ip2long
(
'127.0.0.1'
);
$data
[
'update_time'
]
=
0
;
$role
=
Yii
::
$app
->
request
->
post
(
'role'
,
'administrator'
);
/* 表单数据加载和验证,具体验证规则在模型rule中配置 */
/* 密码单独验证,否则setPassword后密码肯定符合rule */
if
(
empty
(
$data
[
'password'
])
||
strlen
(
$data
[
'password'
])
<
6
)
{
$this
->
error
(
'密码为空或小于6字符'
);
}
$data
=
Yii
::
$app
->
request
->
post
(
'Admin'
);
$model
->
setAttributes
(
$data
);
$model
->
generateAuthKey
();
$model
->
setPassword
(
$data
[
'password'
]);
$model
->
group
=
$role
;
if
(
!
empty
(
$data
[
'password'
]))
{
$model
->
generateAuthKey
();
$model
->
setPassword
(
$data
[
'password'
]);
}
/* 保存用户数据到数据库 */
if
(
$model
->
save
())
{
$auth
=
Yii
::
$app
->
authManager
;
$role
=
$auth
->
getRole
(
$role
);
$auth
->
assign
(
$role
,
$model
->
uid
);
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
}
else
{
$this
->
error
(
'操作错误'
);
}
}
$model
->
password
=
''
;
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
,
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
)
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
)
,
]);
}
}
common/modelsgii/Admin.php
View file @
8d008f67
...
...
@@ -34,7 +34,7 @@ class Admin extends \common\core\BaseActiveRecord
public
function
rules
()
{
return
[
[[
'username'
,
'
password'
,
'
salt'
],
'required'
],
[[
'username'
,
'salt'
],
'required'
],
[
[
'username'
,
'password'
],
'filter'
,
...
...
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