Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
83ab0f06
Commit
83ab0f06
authored
Nov 16, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring
parent
979e8d16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
20 deletions
+18
-20
LoginForm.php
apps/advanced/common/models/LoginForm.php
+9
-10
LoginForm.php
apps/basic/models/LoginForm.php
+9
-10
No files found.
apps/advanced/common/models/LoginForm.php
View file @
83ab0f06
...
...
@@ -13,7 +13,8 @@ class LoginForm extends Model
public
$username
;
public
$password
;
public
$rememberMe
=
true
;
private
$_users
=
[];
private
$_user
=
false
;
/**
* @return array the validation rules.
...
...
@@ -36,7 +37,7 @@ class LoginForm extends Model
*/
public
function
validatePassword
()
{
$user
=
$this
->
getUser
ByUsername
(
$this
->
username
);
$user
=
$this
->
getUser
(
);
if
(
!
$user
||
!
$user
->
validatePassword
(
$this
->
password
))
{
$this
->
addError
(
'password'
,
'Incorrect username or password.'
);
}
...
...
@@ -49,24 +50,22 @@ class LoginForm extends Model
public
function
login
()
{
if
(
$this
->
validate
())
{
$user
=
$this
->
getUserByUsername
(
$this
->
username
);
return
Yii
::
$app
->
user
->
login
(
$user
,
$this
->
rememberMe
?
3600
*
24
*
30
:
0
);
return
Yii
::
$app
->
user
->
login
(
$this
->
getUser
(),
$this
->
rememberMe
?
3600
*
24
*
30
:
0
);
}
else
{
return
false
;
}
}
/**
* Finds user by
username
* Finds user by
[[username]]
*
* @param string $username
* @return User|null
*/
private
function
getUser
ByUsername
(
$username
)
private
function
getUser
(
)
{
if
(
empty
(
$this
->
_users
[
$username
])
)
{
$this
->
_user
s
[
$username
]
=
User
::
findByUsername
(
$
username
);
if
(
$this
->
_user
===
false
)
{
$this
->
_user
=
User
::
findByUsername
(
$this
->
username
);
}
return
$this
->
_user
s
[
$username
]
;
return
$this
->
_user
;
}
}
apps/basic/models/LoginForm.php
View file @
83ab0f06
...
...
@@ -13,7 +13,8 @@ class LoginForm extends Model
public
$username
;
public
$password
;
public
$rememberMe
=
true
;
private
$_users
=
[];
private
$_user
=
false
;
/**
* @return array the validation rules.
...
...
@@ -36,7 +37,7 @@ class LoginForm extends Model
*/
public
function
validatePassword
()
{
$user
=
$this
->
getUser
ByUsername
(
$this
->
username
);
$user
=
$this
->
getUser
(
);
if
(
!
$user
||
!
$user
->
validatePassword
(
$this
->
password
))
{
$this
->
addError
(
'password'
,
'Incorrect username or password.'
);
}
...
...
@@ -49,24 +50,22 @@ class LoginForm extends Model
public
function
login
()
{
if
(
$this
->
validate
())
{
$user
=
$this
->
getUserByUsername
(
$this
->
username
);
return
Yii
::
$app
->
user
->
login
(
$user
,
$this
->
rememberMe
?
3600
*
24
*
30
:
0
);
return
Yii
::
$app
->
user
->
login
(
$this
->
getUser
(),
$this
->
rememberMe
?
3600
*
24
*
30
:
0
);
}
else
{
return
false
;
}
}
/**
* Finds user by
username
* Finds user by
[[username]]
*
* @param string $username
* @return User|null
*/
private
function
getUser
ByUsername
(
$username
)
private
function
getUser
(
)
{
if
(
empty
(
$this
->
_users
[
$username
])
)
{
$this
->
_user
s
[
$username
]
=
User
::
findByUsername
(
$
username
);
if
(
$this
->
_user
===
false
)
{
$this
->
_user
=
User
::
findByUsername
(
$this
->
username
);
}
return
$this
->
_user
s
[
$username
]
;
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