Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
6178a968
Commit
6178a968
authored
Oct 09, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #110 from ericbarnes/feature/remember_me
Feature/remember me
parents
b7b5451a
6e0d69e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
2 deletions
+32
-2
laravel/security/auth.php
+32
-2
No files found.
laravel/security/auth.php
View file @
6178a968
...
...
@@ -52,7 +52,19 @@ class Auth {
$id
=
IoC
::
container
()
->
core
(
'session'
)
->
get
(
Auth
::
user_key
);
return
static
::
$user
=
call_user_func
(
Config
::
get
(
'auth.user'
),
$id
);
static
::
$user
=
call_user_func
(
Config
::
get
(
'auth.user'
),
$id
);
if
(
is_null
(
static
::
$user
)
AND
!
is_null
(
$cookie
=
Crypter
::
decrypt
(
\Cookie
::
get
(
'remember'
))))
{
$cookie
=
explode
(
'|'
,
$cookie
);
if
(
$cookie
[
2
]
==
md5
(
\Request
::
server
(
'HTTP_USER_AGENT'
))
AND
!
is_null
(
static
::
$user
=
call_user_func
(
Config
::
get
(
'auth.user'
),
$cookie
[
0
])))
{
static
::
login
(
static
::
$user
);
}
}
return
static
::
$user
;
}
/**
...
...
@@ -63,14 +75,18 @@ class Auth {
*
* @param string $username
* @param string $password
* @param bool $remember
* @param int $ttl - Default is one week.
* @return bool
*/
public
static
function
attempt
(
$username
,
$password
=
null
)
public
static
function
attempt
(
$username
,
$password
=
null
,
$remember
=
false
,
$ttl
=
10080
)
{
if
(
!
is_null
(
$user
=
call_user_func
(
Config
::
get
(
'auth.attempt'
),
$username
,
$password
)))
{
static
::
login
(
$user
);
if
(
$remember
)
static
::
remember
(
$user
);
return
true
;
}
...
...
@@ -108,4 +124,17 @@ class Auth {
IoC
::
container
()
->
core
(
'session'
)
->
forget
(
Auth
::
user_key
);
}
/**
* Set a cookie so that users are remembered.
*
* @param object $user
* @param int $ttl - Default is one week.
* @return bool
*/
public
static
function
remember
(
$user
,
$ttl
=
10080
)
{
static
::
$user
=
$user
;
$cookie
=
Crypter
::
encrypt
(
implode
(
'|'
,
array
(
$user
->
id
,
\Request
::
ip
(),
md5
(
\Request
::
server
(
'HTTP_USER_AGENT'
)),
time
())));
\Cookie
::
put
(
'remember'
,
$cookie
,
$ttl
);
}
}
\ 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