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
24b1b79f
Commit
24b1b79f
authored
Jun 01, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录
parent
b763b6a3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
119 deletions
+54
-119
main.php
backend/config/main.php
+0
-3
params.php
backend/config/params.php
+4
-5
LoginController.php
backend/controllers/LoginController.php
+44
-92
login.php
backend/views/login/login.php
+0
-13
main.php
common/config/main.php
+3
-3
NewLoginForm.php
common/models/NewLoginForm.php
+3
-3
No files found.
backend/config/main.php
View file @
24b1b79f
...
@@ -16,7 +16,6 @@ return [
...
@@ -16,7 +16,6 @@ return [
'layout'
=>
'main'
,
'layout'
=>
'main'
,
'modules'
=>
[],
'modules'
=>
[],
'components'
=>
[
'components'
=>
[
'request'
=>
[
'request'
=>
[
'class'
=>
'common\core\Request'
,
'class'
=>
'common\core\Request'
,
'baseUrl'
=>
'/admin'
,
'baseUrl'
=>
'/admin'
,
...
@@ -29,7 +28,6 @@ return [
...
@@ -29,7 +28,6 @@ return [
'errorHandler'
=>
[
'errorHandler'
=>
[
'errorAction'
=>
'public/error'
,
'errorAction'
=>
'public/error'
,
],
],
'urlManager'
=>
[
'urlManager'
=>
[
'class'
=>
'common\core\UrlManager'
,
'class'
=>
'common\core\UrlManager'
,
'enablePrettyUrl'
=>
true
,
'enablePrettyUrl'
=>
true
,
...
@@ -37,7 +35,6 @@ return [
...
@@ -37,7 +35,6 @@ return [
'rules'
=>
[
'rules'
=>
[
],
],
]
]
],
],
'params'
=>
$params
,
'params'
=>
$params
,
];
];
backend/config/params.php
View file @
24b1b79f
<?php
<?php
return
[
return
[
'adminEmail'
=>
'admin@example.com'
,
'adminEmail'
=>
'admin@example.com'
,
/* 后台错误页面模板 */
/* 后台错误页面模板 */
'action_error'
=>
'@backend/views/public/error.php'
,
// 默认错误跳转对应的模板文件
'action_error'
=>
'@backend/views/public/error.php'
,
// 默认错误跳转对应的模板文件
'action_success'
=>
'@backend/views/public/success.php'
,
// 默认成功跳转对应的模板文件
'action_success'
=>
'@backend/views/public/success.php'
,
// 默认成功跳转对应的模板文件
];
];
backend/controllers/LoginController.php
View file @
24b1b79f
...
@@ -37,7 +37,7 @@ class LoginController extends Controller
...
@@ -37,7 +37,7 @@ class LoginController extends Controller
'rules'
=>
[
'rules'
=>
[
[
[
'actions'
=>
[
'login'
,
'error'
,
'logout'
],
'actions'
=>
[
'login'
,
'error'
,
'logout'
],
'allow'
=>
true
,
'allow'
=>
true
,
],
],
],
],
],
],
...
@@ -56,98 +56,50 @@ class LoginController extends Controller
...
@@ -56,98 +56,50 @@ class LoginController extends Controller
];
];
}
}
/**
public
function
actionLogin
()
* ---------------------------------------
{
* 二级登录
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
* ---------------------------------------
return
$this
->
goHome
();
*/
}
public
function
actionLogin
()
{
$error
=
null
;
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
$name
=
isset
(
Yii
::
$app
->
request
->
post
(
'info'
)[
'username'
])
?
Yii
::
$app
->
request
->
post
(
'info'
)[
'username'
]
:
null
;
return
$this
->
goHome
();
if
(
Yii
::
$app
->
request
->
isPost
)
{
}
$model
=
new
NewLoginForm
();
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
(),
'info'
))
{
$error
=
null
;
if
(
$model
->
login
())
{
$name
=
isset
(
Yii
::
$app
->
request
->
post
(
'info'
)[
'username'
])
?
Yii
::
$app
->
request
->
post
(
'info'
)[
'username'
]
:
null
;
//更新时间
if
(
Yii
::
$app
->
request
->
isPost
)
{
\common\modelsgii\Admin
::
updateAll
([
'last_login_time'
=>
time
()],
$model
=
new
NewLoginForm
();
[
'username'
=>
$model
->
username
]);
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
(),
'info'
))
{
//重复登陆判断
if
(
!
in_array
(
$model
->
type
,
[
1
,
2
]))
if
(
isset
(
Yii
::
$app
->
getBehavior
(
'check'
)
->
filter
)
&&
Yii
::
$app
->
getBehavior
(
'check'
)
->
filter
===
true
)
{
$code
=
'LOGIN_001'
;
//使用session和表gli_admin_session记录登录账号的token:time&id&ip,并进行MD5加密
else
{
$id
=
Yii
::
$app
->
user
->
id
;
//登录用户的ID
//fxee登录
$username
=
$model
->
username
;
//登录账号
$info
=
null
;
$ip
=
Yii
::
$app
->
request
->
userIP
;
//登录用户主机IP
if
(
$model
->
type
==
1
)
{
$token
=
md5
(
sprintf
(
"%s&%s&%s"
,
time
(),
$id
,
$ip
));
$info
=
LoginBusiness
::
Login
();
$session
=
Yii
::
$app
->
session
;
//$adminOne = Admin::findOne(['username' => $model->username]);
$session
->
set
(
md5
(
sprintf
(
"%s&%s"
,
$id
,
$username
)),
$token
);
//将token存到session变量中
//$fxeeOne = isset($adminOne['bind_uid']) ? FxeeAuth::findOne(['user_id' => $adminOne['bind_uid']]) : null;
AdminSession
::
insertSession
(
$id
,
$token
);
//将token存到tbl_admin_session
/*if (!$fxeeOne || time() >= ($fxeeOne->addtime + $fxeeOne->expires) ) {
}
$info = LoginBusiness::Login();
}*/
return
$this
->
goHome
();
$model
->
password
=
$model
->
password
.
'_auto'
;
}
}
else
{
$code
=
isset
(
$info
)
&&
is_string
(
$info
)
?
$info
:
'LOGIN_002'
;
if
(
$model
->
login
())
{
$del
=
Admin
::
findOne
([
'username'
=>
$model
->
username
]);
//set fxee
if
(
$del
)
{
if
(
$model
->
type
==
1
$del
->
delete
();
&&
isset
(
$info
[
'userid'
])
}
&&
isset
(
$info
[
'access_token'
])
}
&&
isset
(
$info
[
'refresh_token'
])
}
&&
isset
(
$info
[
'expires_in'
])
)
{
$error
=
Yii
::
t
(
'error'
,
$code
);
}
$save
=
FxeeAuth
::
findOne
([
'user_id'
=>
$info
[
'userid'
]]);
if
(
!
$save
)
return
$this
->
render
(
'login'
,
[
'error'
=>
$error
,
'name'
=>
$name
]);
$save
=
new
FxeeAuth
();
}
$save
->
user_id
=
$info
[
'userid'
];
$save
->
access_token
=
$info
[
'access_token'
];
$save
->
refresh_token
=
$info
[
'refresh_token'
];
$save
->
expires
=
$info
[
'expires_in'
];
$save
->
scope
=
isset
(
$info
[
'scope'
])
?
$info
[
'scope'
]
:
null
;
$save
->
addtime
=
time
();
$save
->
save
(
false
);
//save失败时,无权限
}
//更新时间
\common\modelsgii\Admin
::
updateAll
([
'last_login_time'
=>
time
()],
[
'username'
=>
$model
->
username
]);
//重复登陆判断
if
(
isset
(
Yii
::
$app
->
getBehavior
(
'check'
)
->
filter
)
&&
Yii
::
$app
->
getBehavior
(
'check'
)
->
filter
===
true
)
{
//使用session和表gli_admin_session记录登录账号的token:time&id&ip,并进行MD5加密
$id
=
Yii
::
$app
->
user
->
id
;
//登录用户的ID
$username
=
$model
->
username
;
//登录账号
$ip
=
Yii
::
$app
->
request
->
userIP
;
//登录用户主机IP
$token
=
md5
(
sprintf
(
"%s&%s&%s"
,
time
(),
$id
,
$ip
));
$session
=
Yii
::
$app
->
session
;
$session
->
set
(
md5
(
sprintf
(
"%s&%s"
,
$id
,
$username
)),
$token
);
//将token存到session变量中
AdminSession
::
insertSession
(
$id
,
$token
);
//将token存到tbl_admin_session
}
return
$this
->
goHome
();
}
else
{
$code
=
isset
(
$info
)
&&
is_string
(
$info
)
?
$info
:
'LOGIN_002'
;
$del
=
Admin
::
findOne
([
'username'
=>
$model
->
username
]);
if
(
$del
)
$del
->
delete
();
}
}
}
else
{
$code
=
'LOGIN_002'
;
}
$error
=
Yii
::
t
(
'error'
,
$code
);
}
return
$this
->
render
(
'login'
,
[
'error'
=>
$error
,
'name'
=>
$name
]);
}
/**
* ---------------------------------------
* 注销页
* ---------------------------------------
*/
public
function
actionLogout
()
public
function
actionLogout
()
{
{
Yii
::
$app
->
user
->
logout
();
Yii
::
$app
->
user
->
logout
();
...
...
backend/views/login/login.php
View file @
24b1b79f
...
@@ -64,19 +64,6 @@ $this->beginPage();
...
@@ -64,19 +64,6 @@ $this->beginPage();
<input
class=
"form-control placeholder-no-fix"
type=
"password"
autocomplete=
"off"
placeholder=
"密码"
name=
"info[password]"
/>
</div>
<input
class=
"form-control placeholder-no-fix"
type=
"password"
autocomplete=
"off"
placeholder=
"密码"
name=
"info[password]"
/>
</div>
</div>
</div>
<div
class=
"form-group"
style=
"padding-top: 15px;margin-bottom: 0;display: none"
>
<label
class=
"mt-radio mt-radio-outline"
>
<input
type=
"radio"
name=
"info[type]"
value=
"1"
checked
/>
<span></span>
fxee用户
</label>
<label
class=
"mt-radio mt-radio-outline"
>
<input
type=
"radio"
name=
"info[type]"
value=
"2"
/>
<span></span>
后台用户
</label>
</div>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
<label
class=
"checkbox"
>
<label
class=
"checkbox"
>
<input
type=
"checkbox"
name=
"info[rememberMe]"
value=
"1"
/>
记住密码
</label>
<input
type=
"checkbox"
name=
"info[rememberMe]"
value=
"1"
/>
记住密码
</label>
...
...
common/config/main.php
View file @
24b1b79f
...
@@ -39,9 +39,9 @@ return [
...
@@ -39,9 +39,9 @@ return [
*/
*/
'db'
=>
[
'db'
=>
[
'class'
=>
'yii\db\Connection'
,
'class'
=>
'yii\db\Connection'
,
'dsn'
=>
'mysql:host=
rm-bp144nc2129h43c4i.mysql.rds.aliyuncs.com
;dbname=manage'
,
'dsn'
=>
'mysql:host=
127.0.0.1
;dbname=manage'
,
'username'
=>
'
fzmrisk
'
,
'username'
=>
'
root
'
,
'password'
=>
'
37uIrcBFk4nMnUjQ
'
,
'password'
=>
'
123456
'
,
'charset'
=>
'utf8'
,
'charset'
=>
'utf8'
,
'tablePrefix'
=>
'gli_'
,
'tablePrefix'
=>
'gli_'
,
],
],
...
...
common/models/NewLoginForm.php
View file @
24b1b79f
<?php
<?php
namespace
common\models
;
namespace
common\models
;
use
Yii
;
use
Yii
;
...
@@ -12,7 +13,6 @@ class NewLoginForm extends BaseModel
...
@@ -12,7 +13,6 @@ class NewLoginForm extends BaseModel
{
{
public
$username
;
public
$username
;
public
$password
;
public
$password
;
public
$type
;
public
$rememberMe
=
true
;
public
$rememberMe
=
true
;
/**
/**
...
@@ -28,7 +28,7 @@ class NewLoginForm extends BaseModel
...
@@ -28,7 +28,7 @@ class NewLoginForm extends BaseModel
{
{
return
[
return
[
// username and password are both required
// username and password are both required
[[
'username'
,
'password'
,
'type'
],
'required'
],
[[
'username'
,
'password'
],
'required'
],
// password is validated by validatePassword()
// password is validated by validatePassword()
[
'password'
,
'validatePassword'
],
[
'password'
,
'validatePassword'
],
// rememberMe must be a boolean value
// rememberMe must be a boolean value
...
@@ -75,7 +75,7 @@ class NewLoginForm extends BaseModel
...
@@ -75,7 +75,7 @@ class NewLoginForm extends BaseModel
public
function
getUser
()
public
function
getUser
()
{
{
if
(
$this
->
_user
===
null
)
{
if
(
$this
->
_user
===
null
)
{
$this
->
_user
=
Admin
::
findByUsername
(
$this
->
username
);
$this
->
_user
=
Admin
::
findByUsername
(
$this
->
username
);
}
}
return
$this
->
_user
;
return
$this
->
_user
;
...
...
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