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
5759fa1c
Commit
5759fa1c
authored
Nov 25, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
e5bf1d57
'
* commit '
e5bf1d57
': Squashed 'Modules/User/' changes from 4cfd87c..a241ed9
parents
f433735f
e5bf1d57
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
319 additions
and
5 deletions
+319
-5
SentinelUser.php
Modules/User/Entities/SentinelUser.php
+2
-2
SentryUser.php
Modules/User/Entities/SentryUser.php
+19
-0
SentinelUserRepository.php
...les/User/Repositories/Sentinel/SentinelUserRepository.php
+1
-1
SentryAuthentication.php
Modules/User/Repositories/Sentry/SentryAuthentication.php
+115
-0
SentryRoleRepository.php
Modules/User/Repositories/Sentry/SentryRoleRepository.php
+72
-0
SentryUserRepository.php
Modules/User/Repositories/Sentry/SentryUserRepository.php
+108
-0
UserRepository.php
Modules/User/Repositories/UserRepository.php
+2
-2
No files found.
Modules/User/Entities/User.php
→
Modules/User/Entities/
Sentinel
User.php
View file @
5759fa1c
<?php
namespace
Modules\User\Entities
;
use
Cartalyst\Sentinel\Users\EloquentUser
as
SentryUser
;
use
Cartalyst\Sentinel\Users\EloquentUser
;
use
Laracasts\Presenter\PresentableTrait
;
class
User
extends
Sentry
User
class
SentinelUser
extends
Eloquent
User
{
use
PresentableTrait
;
...
...
Modules/User/Entities/SentryUser.php
0 → 100644
View file @
5759fa1c
<?php
namespace
Modules\User\Entities
;
use
Cartalyst\Sentry\Users\Eloquent\User
;
use
Laracasts\Presenter\PresentableTrait
;
class
SentryUser
extends
User
{
use
PresentableTrait
;
protected
$fillable
=
[
'email'
,
'password'
,
'permissions'
,
'first_name'
,
'last_name'
];
protected
$presenter
=
'Modules\User\Presenters\UserPresenter'
;
}
Modules/User/Repositories/Sentinel/SentinelUserRepository.php
View file @
5759fa1c
...
...
@@ -8,7 +8,7 @@ use Modules\User\Repositories\UserRepository;
class
SentinelUserRepository
implements
UserRepository
{
/**
* @var \Modules\User\Entities\User
* @var \Modules\User\Entities\
Sentinel
User
*/
protected
$user
;
/**
...
...
Modules/User/Repositories/Sentry/SentryAuthentication.php
0 → 100644
View file @
5759fa1c
<?php
namespace
Modules\User\Repositories\Sentry
;
use
Modules\Core\Contracts\Authentication
;
use
Cartalyst\Sentry\Facades\Laravel\Sentry
;
class
SentryAuthentication
implements
Authentication
{
/**
* Authenticate a user
* @param array $credentials
* @param bool $remember Remember the user
* @return mixed
*/
public
function
login
(
array
$credentials
,
$remember
=
false
)
{
if
(
Sentry
::
authenticate
(
$credentials
,
$remember
))
{
return
false
;
}
return
'Invalid login or password.'
;
}
/**
* Register a new user.
* @param array $user
* @return bool
*/
public
function
register
(
array
$user
)
{
return
Sentry
::
register
(
$user
);
}
/**
* Activate the given used id
* @param int $userId
* @param string $code
* @return mixed
*/
public
function
activate
(
$userId
,
$code
)
{
$user
=
Sentry
::
findUserById
(
$userId
);
return
$user
->
attemptActivation
(
$code
);
}
/**
* Assign a role to the given user.
* @param \Modules\User\Repositories\UserRepository $user
* @param \Modules\User\Repositories\RoleRepository $role
* @return mixed
*/
public
function
assignRole
(
$user
,
$role
)
{
return
$role
->
users
()
->
attach
(
$user
);
}
/**
* Log the user out of the application.
* @return mixed
*/
public
function
logout
()
{
return
Sentry
::
logout
();
}
/**
* Create an activation code for the given user
* @param $user
* @return mixed
*/
public
function
createActivation
(
$user
)
{
return
$user
->
getResetPasswordCode
();
}
/**
* Create a reminders code for the given user
* @param $user
* @return mixed
*/
public
function
createReminderCode
(
$user
)
{
return
$user
->
getResetPasswordCode
();
}
/**
* Completes the reset password process
* @param $user
* @param string $code
* @param string $password
* @return bool
*/
public
function
completeResetPassword
(
$user
,
$code
,
$password
)
{
return
$user
->
attemptResetPassword
(
$code
,
$password
);
}
/**
* Determines if the current user has access to given permission
* @param $permission
* @return bool
*/
public
function
hasAccess
(
$permission
)
{
return
Sentry
::
hasAccess
(
$permission
);
}
/**
* Check if the user is logged in
* @return mixed
*/
public
function
check
()
{
return
Sentry
::
check
();
}
}
Modules/User/Repositories/Sentry/SentryRoleRepository.php
0 → 100644
View file @
5759fa1c
<?php
namespace
Modules\User\Repositories\Sentry
;
use
Modules\User\Repositories\RoleRepository
;
use
Cartalyst\Sentry\Facades\Laravel\Sentry
;
class
SentryRoleRepository
implements
RoleRepository
{
/**
* Return all the roles
* @return mixed
*/
public
function
all
()
{
return
Sentry
::
findAllGroups
();
}
/**
* Create a role resource
* @return mixed
*/
public
function
create
(
$data
)
{
Sentry
::
createGroup
(
$data
);
}
/**
* Find a role by its id
* @param $id
* @return mixed
*/
public
function
find
(
$id
)
{
return
Sentry
::
findGroupById
(
$id
);
}
/**
* Update a role
* @param $id
* @param $data
* @return mixed
*/
public
function
update
(
$id
,
$data
)
{
$role
=
Sentry
::
findGroupById
(
$id
);
$role
->
permissions
(
$data
);
$role
->
save
();
}
/**
* Delete a role
* @param $id
* @return mixed
*/
public
function
delete
(
$id
)
{
$role
=
Sentry
::
findGroupById
(
$id
);
return
$role
->
delete
();
}
/**
* Find a role by its name
* @param string $name
* @return mixed
*/
public
function
findByName
(
$name
)
{
return
Sentry
::
findGroupByName
(
$name
);
}
}
Modules/User/Repositories/Sentry/SentryUserRepository.php
0 → 100644
View file @
5759fa1c
<?php
namespace
Modules\User\Repositories\Sentry
;
use
Modules\User\Repositories\UserRepository
;
use
Cartalyst\Sentry\Facades\Laravel\Sentry
;
class
SentryUserRepository
implements
UserRepository
{
/**
* Returns all the users
* @return object
*/
public
function
all
()
{
return
Sentry
::
findAllUsers
();
}
/**
* Create a user resource
* @param array $data
* @return mixed
*/
public
function
create
(
array
$data
)
{
return
Sentry
::
createUser
(
$data
);
}
/**
* Create a user and assign roles to it
* @param array $data
* @param array $roles
* @return void
*/
public
function
createWithRoles
(
$data
,
$roles
)
{
$user
=
Sentry
::
createUser
(
$data
);
if
(
!
empty
(
$roles
))
{
$group
=
Sentry
::
findGroupByName
(
$roles
);
$user
->
addGroup
(
$group
);
}
$user
->
attemptActivation
(
$user
->
getActivationCode
());
}
/**
* Find a user by its ID
* @param $id
* @return mixed
*/
public
function
find
(
$id
)
{
return
Sentry
::
findUserById
(
$id
);
}
/**
* Update a user
* @param $user
* @param $data
* @return mixed
*/
public
function
update
(
$user
,
$data
)
{
$user
=
$user
->
update
(
$data
);
return
$user
->
save
();
}
/**
* Update a user and sync its roles
* @param int $userId
* @param $data
* @param $roles
* @return mixed
*/
public
function
updateAndSyncRoles
(
$userId
,
$data
,
$roles
)
{
$user
=
Sentry
::
findUserById
(
$userId
);
$user
=
$user
->
update
(
$data
);
$user
->
save
();
if
(
!
empty
(
$roles
))
{
$adminGroup
=
Sentry
::
findGroupByName
(
$roles
);
$user
->
removeGroup
();
$user
->
addGroup
(
$adminGroup
);
}
}
/**
* Deletes a user
* @param $id
* @return mixed
* @throws UserNotFoundException
*/
public
function
delete
(
$id
)
{
if
(
$user
=
Sentry
::
findUserById
(
$id
))
{
return
$user
->
delete
();
};
throw
new
UserNotFoundException
;
}
/**
* Find a user by its credentials
* @param array $credentials
* @return mixed
*/
public
function
findByCredentials
(
array
$credentials
)
{
return
Sentry
::
findUserByCredentials
(
$credentials
);
}
}
Modules/User/Repositories/UserRepository.php
View file @
5759fa1c
...
...
@@ -44,12 +44,12 @@ interface UserRepository
/**
* Update a user and sync its roles
* @param
$user
* @param
int $userId
* @param $data
* @param $roles
* @return mixed
*/
public
function
updateAndSyncRoles
(
$user
,
$data
,
$roles
);
public
function
updateAndSyncRoles
(
$user
Id
,
$data
,
$roles
);
/**
* Deletes a 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