Commit 5759fa1c authored by Nicolas Widart's avatar Nicolas Widart

Merge commit 'e5bf1d57'

* commit 'e5bf1d57':
  Squashed 'Modules/User/' changes from 4cfd87c..a241ed9
parents f433735f e5bf1d57
<?php namespace Modules\User\Entities;
use Cartalyst\Sentinel\Users\EloquentUser as SentryUser;
use Cartalyst\Sentinel\Users\EloquentUser;
use Laracasts\Presenter\PresentableTrait;
class User extends SentryUser
class SentinelUser extends EloquentUser
{
use PresentableTrait;
......
<?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';
}
......@@ -8,7 +8,7 @@ use Modules\User\Repositories\UserRepository;
class SentinelUserRepository implements UserRepository
{
/**
* @var \Modules\User\Entities\User
* @var \Modules\User\Entities\SentinelUser
*/
protected $user;
/**
......
<?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();
}
}
<?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);
}
}
<?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);
}
}
......@@ -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($userId, $data, $roles);
/**
* Deletes a user
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment