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
187b3423
Commit
187b3423
authored
Aug 07, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
3a6a6435
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletion
+40
-1
AdminController.php
backend/controllers/AdminController.php
+40
-1
No files found.
backend/controllers/AdminController.php
View file @
187b3423
...
...
@@ -63,7 +63,7 @@ class AdminController extends BaseController
if
(
$model
->
save
())
{
$auth
=
Yii
::
$app
->
authManager
;
$role
=
$auth
->
getRole
(
$role
);
$auth
->
assign
(
$role
,
$model
->
uid
);
$auth
->
assign
(
$role
,
$model
->
uid
);
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
}
else
{
$this
->
error
(
'操作错误'
);
...
...
@@ -116,4 +116,43 @@ class AdminController extends BaseController
]);
}
public
function
actionEdit
()
{
$model
=
new
Admin
();
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字符'
);
}
$model
->
setAttributes
(
$data
);
$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
(
'操作错误'
);
}
}
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
,
'role'
=>
Yii
::
$app
->
request
->
get
(
'role'
,
'administrator'
)
]);
}
}
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