Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
Platform
Commits
22e864e0
Unverified
Commit
22e864e0
authored
Jul 19, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a sentinel guard allowing usage of the Auth:: facade and native auth related methods
parent
eab3a7fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
3 deletions
+98
-3
User.php
Modules/User/Entities/Sentinel/User.php
+4
-2
Sentinel.php
Modules/User/Guards/Sentinel.php
+87
-0
UserServiceProvider.php
Modules/User/Providers/UserServiceProvider.php
+6
-0
auth.php
config/auth.php
+1
-1
No files found.
Modules/User/Entities/Sentinel/User.php
View file @
22e864e0
...
...
@@ -2,6 +2,8 @@
namespace
Modules\User\Entities\Sentinel
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Auth\Authenticatable
;
use
Cartalyst\Sentinel\Laravel\Facades\Activation
;
use
Cartalyst\Sentinel\Users\EloquentUser
;
use
Laracasts\Presenter\PresentableTrait
;
...
...
@@ -9,9 +11,9 @@ use Modules\User\Entities\UserInterface;
use
Modules\User\Entities\UserToken
;
use
Modules\User\Presenters\UserPresenter
;
class
User
extends
EloquentUser
implements
UserInterface
class
User
extends
EloquentUser
implements
UserInterface
,
AuthenticatableContract
{
use
PresentableTrait
;
use
PresentableTrait
,
Authenticatable
;
protected
$fillable
=
[
'email'
,
...
...
Modules/User/Guards/Sentinel.php
0 → 100644
View file @
22e864e0
<?php
namespace
Modules\User\Guards
;
use
Cartalyst\Sentinel\Laravel\Facades\Sentinel
as
SentinelFacade
;
use
Illuminate\Contracts\Auth\Authenticatable
;
use
Illuminate\Contracts\Auth\Guard
as
LaravelGuard
;
class
Sentinel
implements
LaravelGuard
{
/**
* Determine if the current user is authenticated.
* @return bool
*/
public
function
check
()
{
if
(
SentinelFacade
::
check
())
{
return
true
;
}
return
false
;
}
/**
* Determine if the current user is a guest.
* @return bool
*/
public
function
guest
()
{
return
SentinelFacade
::
guest
();
}
/**
* Get the currently authenticated user.
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public
function
user
()
{
return
SentinelFacade
::
getUser
();
}
/**
* Get the ID for the currently authenticated user.
* @return int|null
*/
public
function
id
()
{
if
(
$user
=
SentinelFacade
::
check
())
{
return
$user
->
id
;
}
return
null
;
}
/**
* Validate a user's credentials.
* @param array $credentials
* @return bool
*/
public
function
validate
(
array
$credentials
=
[])
{
return
SentinelFacade
::
validForCreation
(
$credentials
);
}
/**
* Set the current user.
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public
function
setUser
(
Authenticatable
$user
)
{
SentinelFacade
::
login
(
$user
);
}
/**
* Alias to set the current user.
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public
function
login
(
Authenticatable
$user
)
{
$this
->
setUser
(
$user
);
}
public
function
attempt
(
array
$credentials
,
$remember
=
false
)
{
return
SentinelFacade
::
authenticate
(
$credentials
,
$remember
);
}
}
Modules/User/Providers/UserServiceProvider.php
View file @
22e864e0
...
...
@@ -3,6 +3,7 @@
namespace
Modules\User\Providers
;
use
Cartalyst\Sentinel\Laravel\SentinelServiceProvider
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\ServiceProvider
;
use
Modules\Core\Traits\CanPublishConfiguration
;
use
Modules\User\Contracts\Authentication
;
...
...
@@ -17,6 +18,7 @@ use Modules\User\Repositories\Eloquent\EloquentUserTokenRepository;
use
Modules\User\Repositories\RoleRepository
;
use
Modules\User\Repositories\UserRepository
;
use
Modules\User\Repositories\UserTokenRepository
;
use
Modules\User\Guards\Sentinel
;
class
UserServiceProvider
extends
ServiceProvider
{
...
...
@@ -72,6 +74,10 @@ class UserServiceProvider extends ServiceProvider
$this
->
publishConfig
(
'user'
,
'config'
);
$this
->
loadMigrationsFrom
(
__DIR__
.
'/../Database/Migrations'
);
Auth
::
extend
(
'sentinel-guard'
,
function
()
{
return
new
Sentinel
();
});
}
/**
...
...
config/auth.php
View file @
22e864e0
...
...
@@ -37,7 +37,7 @@ return [
'guards'
=>
[
'web'
=>
[
'driver'
=>
'se
ssion
'
,
'driver'
=>
'se
ntinel-guard
'
,
'provider'
=>
'users'
,
],
...
...
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