Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
69d9257a
Commit
69d9257a
authored
May 29, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return value of cookie.
parent
91c64b38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
224 additions
and
224 deletions
+224
-224
driver.php
laravel/auth/drivers/driver.php
+223
-223
cookie.php
laravel/cookie.php
+1
-1
No files found.
laravel/auth/drivers/driver.php
View file @
69d9257a
<?php
namespace
Laravel\Auth\Drivers
;
<?php
namespace
Laravel\Auth\Drivers
;
use
Laravel\Str
;
use
Laravel\Str
;
use
Laravel\Cookie
;
use
Laravel\Cookie
;
use
Laravel\Config
;
use
Laravel\Config
;
use
Laravel\Session
;
use
Laravel\Session
;
use
Laravel\Crypter
;
use
Laravel\Crypter
;
abstract
class
Driver
{
abstract
class
Driver
{
/**
/**
* The user currently being managed by the driver.
* The user currently being managed by the driver.
*
*
* @var mixed
* @var mixed
*/
*/
public
$user
;
public
$user
;
/**
/**
* The current value of the user's token.
* The current value of the user's token.
*
*
* @var string|null
* @var string|null
*/
*/
public
$token
;
public
$token
;
/**
/**
* Create a new login auth driver instance.
* Create a new login auth driver instance.
*
*
* @return void
* @return void
*/
*/
public
function
__construct
()
public
function
__construct
()
{
{
if
(
Session
::
started
())
if
(
Session
::
started
())
{
{
$this
->
token
=
Session
::
get
(
$this
->
token
());
$this
->
token
=
Session
::
get
(
$this
->
token
());
}
}
// If a token did not exist in the session for the user, we will attempt
// If a token did not exist in the session for the user, we will attempt
// to load the value of a "remember me" cookie for the driver, which
// to load the value of a "remember me" cookie for the driver, which
// serves as a long-lived client side authenticator for the user.
// serves as a long-lived client side authenticator for the user.
if
(
is_null
(
$this
->
token
))
if
(
is_null
(
$this
->
token
))
{
{
$this
->
token
=
$this
->
recall
();
$this
->
token
=
$this
->
recall
();
}
}
}
}
/**
/**
* Determine if the user of the application is not logged in.
* Determine if the user of the application is not logged in.
*
*
* This method is the inverse of the "check" method.
* This method is the inverse of the "check" method.
*
*
* @return bool
* @return bool
*/
*/
public
function
guest
()
public
function
guest
()
{
{
return
!
$this
->
check
();
return
!
$this
->
check
();
}
}
/**
/**
* Determine if the user is logged in.
* Determine if the user is logged in.
*
*
* @return bool
* @return bool
*/
*/
public
function
check
()
public
function
check
()
{
{
return
!
is_null
(
$this
->
user
());
return
!
is_null
(
$this
->
user
());
}
}
/**
/**
* Get the current user of the application.
* Get the current user of the application.
*
*
* If the user is a guest, null should be returned.
* If the user is a guest, null should be returned.
*
*
* @return mixed|null
* @return mixed|null
*/
*/
public
function
user
()
public
function
user
()
{
{
if
(
!
is_null
(
$this
->
user
))
return
$this
->
user
;
if
(
!
is_null
(
$this
->
user
))
return
$this
->
user
;
return
$this
->
user
=
$this
->
retrieve
(
$this
->
token
);
return
$this
->
user
=
$this
->
retrieve
(
$this
->
token
);
}
}
/**
/**
* Get the a given application user by ID.
* Get the a given application user by ID.
*
*
* @param int $id
* @param int $id
* @return mixed
* @return mixed
*/
*/
abstract
public
function
retrieve
(
$id
);
abstract
public
function
retrieve
(
$id
);
/**
/**
* Attempt to log a user into the application.
* Attempt to log a user into the application.
*
*
* @param array $arguments
* @param array $arguments
* @return void
* @return void
*/
*/
abstract
public
function
attempt
(
$arguments
=
array
());
abstract
public
function
attempt
(
$arguments
=
array
());
/**
/**
* Login the user assigned to the given token.
* Login the user assigned to the given token.
*
*
* The token is typically a numeric ID for the user.
* The token is typically a numeric ID for the user.
*
*
* @param string $token
* @param string $token
* @param bool $remember
* @param bool $remember
* @return bool
* @return bool
*/
*/
public
function
login
(
$token
,
$remember
=
false
)
public
function
login
(
$token
,
$remember
=
false
)
{
{
$this
->
token
=
$token
;
$this
->
token
=
$token
;
$this
->
store
(
$token
);
$this
->
store
(
$token
);
if
(
$remember
)
$this
->
remember
(
$token
);
if
(
$remember
)
$this
->
remember
(
$token
);
return
true
;
return
true
;
}
}
/**
/**
* Log the user out of the driver's auth context.
* Log the user out of the driver's auth context.
*
*
* @return void
* @return void
*/
*/
public
function
logout
()
public
function
logout
()
{
{
$this
->
user
=
null
;
$this
->
user
=
null
;
$this
->
cookie
(
$this
->
recaller
(),
null
,
-
2000
);
$this
->
cookie
(
$this
->
recaller
(),
null
,
-
2000
);
Session
::
forget
(
$this
->
token
());
Session
::
forget
(
$this
->
token
());
}
}
/**
/**
* Store a user's token in the session.
* Store a user's token in the session.
*
*
* @param string $token
* @param string $token
* @return void
* @return void
*/
*/
protected
function
store
(
$token
)
protected
function
store
(
$token
)
{
{
Session
::
put
(
$this
->
token
(),
$token
);
Session
::
put
(
$this
->
token
(),
$token
);
}
}
/**
/**
* Store a user's token in a long-lived cookie.
* Store a user's token in a long-lived cookie.
*
*
* @param string $token
* @param string $token
* @return void
* @return void
*/
*/
protected
function
remember
(
$token
)
protected
function
remember
(
$token
)
{
{
$token
=
Crypter
::
encrypt
(
$token
.
'|'
.
Str
::
random
(
40
));
$token
=
Crypter
::
encrypt
(
$token
.
'|'
.
Str
::
random
(
40
));
$this
->
cookie
(
$this
->
recaller
(),
$token
,
Cookie
::
forever
);
$this
->
cookie
(
$this
->
recaller
(),
$token
,
Cookie
::
forever
);
}
}
/**
/**
* Attempt to find a "remember me" cookie for the user.
* Attempt to find a "remember me" cookie for the user.
*
*
* @return string|null
* @return string|null
*/
*/
protected
function
recall
()
protected
function
recall
()
{
{
$cookie
=
Cookie
::
get
(
$this
->
recaller
());
$cookie
=
Cookie
::
get
(
$this
->
recaller
());
// By default, "remember me" cookies are encrypted and contain the user
// By default, "remember me" cookies are encrypted and contain the user
// token as well as a random string. If it exists, we'll decrypt it
// token as well as a random string. If it exists, we'll decrypt it
// and return the first segment, which is the user's ID token.
// and return the first segment, which is the user's ID token.
if
(
!
is_null
(
$cookie
))
if
(
!
is_null
(
$cookie
))
{
{
return
head
(
explode
(
'|'
,
Crypter
::
decrypt
(
$cookie
)));
return
head
(
explode
(
'|'
,
Crypter
::
decrypt
(
$cookie
)));
}
}
}
}
/**
/**
* Store an authentication cookie.
* Store an authentication cookie.
*
*
* @param string $name
* @param string $name
* @param string $value
* @param string $value
* @param int $minutes
* @param int $minutes
* @return void
* @return void
*/
*/
protected
function
cookie
(
$name
,
$value
,
$minutes
)
protected
function
cookie
(
$name
,
$value
,
$minutes
)
{
{
// When setting the default implementation of an authentication
// When setting the default implementation of an authentication
// cookie we'll use the same settings as the session cookie.
// cookie we'll use the same settings as the session cookie.
// This typically makes sense as they both are sensitive.
// This typically makes sense as they both are sensitive.
$config
=
Config
::
get
(
'session'
);
$config
=
Config
::
get
(
'session'
);
extract
(
$config
);
extract
(
$config
);
Cookie
::
put
(
$name
,
$value
,
$minutes
,
$path
,
$domain
,
$secure
);
Cookie
::
put
(
$name
,
$value
,
$minutes
,
$path
,
$domain
,
$secure
);
}
}
/**
/**
* Get session key name used to store the token.
* Get session key name used to store the token.
*
*
* @return string
* @return string
*/
*/
protected
function
token
()
protected
function
token
()
{
{
return
$this
->
name
()
.
'_login'
;
return
$this
->
name
()
.
'_login'
;
}
}
/**
/**
* Get the name used for the "remember me" cookie.
* Get the name used for the "remember me" cookie.
*
*
* @return string
* @return string
*/
*/
protected
function
recaller
()
protected
function
recaller
()
{
{
return
$this
->
name
()
.
'_remember'
;
return
$this
->
name
()
.
'_remember'
;
}
}
/**
/**
* Get the name of the driver in a storage friendly format.
* Get the name of the driver in a storage friendly format.
*
*
* @return string
* @return string
*/
*/
protected
function
name
()
protected
function
name
()
{
{
return
strtolower
(
str_replace
(
'\\'
,
'_'
,
get_class
(
$this
)));
return
strtolower
(
str_replace
(
'\\'
,
'_'
,
get_class
(
$this
)));
}
}
}
}
\ No newline at end of file
laravel/cookie.php
View file @
69d9257a
...
@@ -44,7 +44,7 @@ class Cookie {
...
@@ -44,7 +44,7 @@ class Cookie {
*/
*/
public
static
function
get
(
$name
,
$default
=
null
)
public
static
function
get
(
$name
,
$default
=
null
)
{
{
if
(
isset
(
static
::
$jar
[
$name
]))
return
static
::
$jar
[
$name
];
if
(
isset
(
static
::
$jar
[
$name
]))
return
static
::
$jar
[
$name
]
[
'value'
]
;
return
array_get
(
Request
::
foundation
()
->
cookies
->
all
(),
$name
,
$default
);
return
array_get
(
Request
::
foundation
()
->
cookies
->
all
(),
$name
,
$default
);
}
}
...
...
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