Commit 6994f095 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/User/' changes from 6206740..8b9a95b

8b9a95b Removing unused dependency
24c7042 Back to abstract class
76219fe Removing the session dependency
66d02c4 Moving the private variable up
7f309c3 Moving the permissions manager one class up
57c0859 Removing unused variable. Refactoring one more method
42c5a2c Refactoring User tests
bae983e Refactoring the Session test
2c9a00b Abstracting the permision partial
2786996 Removing duplicate partial views
7679dfc Type hinting for array
c7e5050 Reactivating the guest filter
a656b76 Removing duplicate role request
45e5b9e Astracting the method
1fedb02 Fixing code duplication
57f57a0 Removing unused import
fc62d29 Removing unused variable
1c68458 Type hinting for the message class
6085e7d Type hinting view class
3b7aaf1 Adding blank line at EOL
fdf1b94 Removing unused helper. Switcher functions to class calls
de0a4f9 Testing new middleware
7491ecc Adding code quality badges
a5c6767 Merge pull request #10 from nWidart-Modules/conforming-to-l5
95558c7 Removing annotations to be sure.
75041d2 New routes SP structure.
a019da9 Adding namespace back to routes file

git-subtree-dir: Modules/User
git-subtree-split: 8b9a95b378ee5d88d1a7112702bc2c25ecd200e3
parent e3d775c7
...@@ -8,4 +8,4 @@ class BeginResetProcessCommand ...@@ -8,4 +8,4 @@ class BeginResetProcessCommand
{ {
$this->email = $email; $this->email = $email;
} }
} }
\ No newline at end of file
...@@ -34,4 +34,4 @@ class BeginResetProcessCommandHandler implements CommandHandler ...@@ -34,4 +34,4 @@ class BeginResetProcessCommandHandler implements CommandHandler
throw new UserNotFoundException(); throw new UserNotFoundException();
} }
} }
\ No newline at end of file
...@@ -14,4 +14,4 @@ class CompleteResetProcessCommand ...@@ -14,4 +14,4 @@ class CompleteResetProcessCommand
$this->userId = $userId; $this->userId = $userId;
$this->code = $code; $this->code = $code;
} }
} }
\ No newline at end of file
...@@ -41,4 +41,4 @@ class CompleteResetProcessCommandHandler implements CommandHandler ...@@ -41,4 +41,4 @@ class CompleteResetProcessCommandHandler implements CommandHandler
throw new UserNotFoundException; throw new UserNotFoundException;
} }
} }
\ No newline at end of file
...@@ -12,4 +12,4 @@ class RegisterNewUserCommand ...@@ -12,4 +12,4 @@ class RegisterNewUserCommand
$this->password = $password; $this->password = $password;
$this->password_confirmation = $password_confirmation; $this->password_confirmation = $password_confirmation;
} }
} }
\ No newline at end of file
...@@ -39,4 +39,4 @@ class RegisterNewUserCommandHandler implements CommandHandler ...@@ -39,4 +39,4 @@ class RegisterNewUserCommandHandler implements CommandHandler
$group->users()->attach($user); $group->users()->attach($user);
} }
} }
\ No newline at end of file
...@@ -19,4 +19,4 @@ class PermissionsViewComposer ...@@ -19,4 +19,4 @@ class PermissionsViewComposer
// Get all permissions // Get all permissions
$view->permissions = $this->permissions->all(); $view->permissions = $this->permissions->all();
} }
} }
\ No newline at end of file
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
use Illuminate\View\View;
class SidebarViewComposer class SidebarViewComposer
{ {
public function compose($view) public function compose(View $view)
{ {
$view->items->put('user', Collection::make([ $view->items->put('user', Collection::make([
[ [
...@@ -29,4 +30,4 @@ class SidebarViewComposer ...@@ -29,4 +30,4 @@ class SidebarViewComposer
] ]
])); ]));
} }
} }
\ No newline at end of file
...@@ -16,4 +16,4 @@ return [ ...@@ -16,4 +16,4 @@ return [
'update', 'update',
'destroy' 'destroy'
], ],
]; ];
\ No newline at end of file
<?php <?php
return [ return [
]; ];
\ No newline at end of file
...@@ -66,4 +66,4 @@ class SentryGroupSeedTableSeeder extends Seeder ...@@ -66,4 +66,4 @@ class SentryGroupSeedTableSeeder extends Seeder
$group->save(); $group->save();
} }
} }
\ No newline at end of file
...@@ -36,4 +36,4 @@ class SentryUserSeedTableSeeder extends Seeder ...@@ -36,4 +36,4 @@ class SentryUserSeedTableSeeder extends Seeder
$adminGroup->users()->attach($user); $adminGroup->users()->attach($user);
} }
} }
\ No newline at end of file
...@@ -17,4 +17,4 @@ class UserDatabaseSeeder extends Seeder ...@@ -17,4 +17,4 @@ class UserDatabaseSeeder extends Seeder
$this->call("Modules\\User\\Database\\Seeders\\SentryGroupSeedTableSeeder"); $this->call("Modules\\User\\Database\\Seeders\\SentryGroupSeedTableSeeder");
} }
} }
\ No newline at end of file
...@@ -10,4 +10,4 @@ class UserHasBegunResetProcess ...@@ -10,4 +10,4 @@ class UserHasBegunResetProcess
$this->user = $user; $this->user = $user;
$this->reminder = $reminder; $this->reminder = $reminder;
} }
} }
\ No newline at end of file
...@@ -8,4 +8,4 @@ class UserHasRegistered ...@@ -8,4 +8,4 @@ class UserHasRegistered
{ {
$this->user = $user; $this->user = $user;
} }
} }
\ No newline at end of file
...@@ -5,4 +5,4 @@ use Exception; ...@@ -5,4 +5,4 @@ use Exception;
class InvalidOrExpiredResetCode extends Exception class InvalidOrExpiredResetCode extends Exception
{ {
} }
\ No newline at end of file
...@@ -5,4 +5,4 @@ use Exception; ...@@ -5,4 +5,4 @@ use Exception;
class UserNotFoundException extends Exception class UserNotFoundException extends Exception
{ {
} }
\ No newline at end of file
<?php namespace Modules\User\Http\Controllers\Admin;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
abstract class BaseUserModuleController extends AdminBaseController
{
/**
* @var PermissionManager
*/
protected $permissions;
/**
* @param $request
* @return array
*/
protected function mergeRequestWithPermissions($request)
{
return array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]);
}
}
...@@ -3,18 +3,12 @@ ...@@ -3,18 +3,12 @@
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash; use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Core\Permissions\PermissionManager; use Modules\Core\Permissions\PermissionManager;
use Modules\User\Http\Requests\CreateRolesRequest; use Modules\User\Http\Requests\RolesRequest;
use Modules\User\Http\Requests\UpdateRoleRequest;
use Modules\User\Repositories\RoleRepository; use Modules\User\Repositories\RoleRepository;
class RolesController extends AdminBaseController class RolesController extends BaseUserModuleController
{ {
/**
* @var PermissionManager
*/
private $permissions;
/** /**
* @var RoleRepository * @var RoleRepository
*/ */
...@@ -23,6 +17,7 @@ class RolesController extends AdminBaseController ...@@ -23,6 +17,7 @@ class RolesController extends AdminBaseController
public function __construct(PermissionManager $permissions, RoleRepository $role) public function __construct(PermissionManager $permissions, RoleRepository $role)
{ {
parent::__construct(); parent::__construct();
$this->permissions = $permissions; $this->permissions = $permissions;
$this->role = $role; $this->role = $role;
} }
...@@ -52,12 +47,12 @@ class RolesController extends AdminBaseController ...@@ -52,12 +47,12 @@ class RolesController extends AdminBaseController
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
* *
* @param CreateRolesRequest $request * @param RolesRequest $request
* @return Response * @return Response
*/ */
public function store(CreateRolesRequest $request) public function store(RolesRequest $request)
{ {
$data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]); $data = $this->mergeRequestWithPermissions($request);
$this->role->create($data); $this->role->create($data);
...@@ -84,12 +79,12 @@ class RolesController extends AdminBaseController ...@@ -84,12 +79,12 @@ class RolesController extends AdminBaseController
* Update the specified resource in storage. * Update the specified resource in storage.
* *
* @param int $id * @param int $id
* @param UpdateRoleRequest $request * @param RolesRequest $request
* @return Response * @return Response
*/ */
public function update($id, UpdateRoleRequest $request) public function update($id, RolesRequest $request)
{ {
$data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]); $data = $this->mergeRequestWithPermissions($request);
$this->role->update($id, $data); $this->role->update($id, $data);
...@@ -110,4 +105,5 @@ class RolesController extends AdminBaseController ...@@ -110,4 +105,5 @@ class RolesController extends AdminBaseController
Flash::success('Role deleted!'); Flash::success('Role deleted!');
return Redirect::route('dashboard.role.index'); return Redirect::route('dashboard.role.index');
} }
}
\ No newline at end of file }
...@@ -3,19 +3,14 @@ ...@@ -3,19 +3,14 @@
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash; use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Core\Permissions\PermissionManager; use Modules\Core\Permissions\PermissionManager;
use Modules\User\Http\Requests\CreateUserRequest; use Modules\User\Http\Requests\CreateUserRequest;
use Modules\User\Http\Requests\UpdateUserRequest; use Modules\User\Http\Requests\UpdateUserRequest;
use Modules\User\Repositories\RoleRepository; use Modules\User\Repositories\RoleRepository;
use Modules\User\Repositories\UserRepository; use Modules\User\Repositories\UserRepository;
class UserController extends AdminBaseController class UserController extends BaseUserModuleController
{ {
/**
* @var PermissionManager
*/
private $permissions;
/** /**
* @var UserRepository * @var UserRepository
*/ */
...@@ -66,7 +61,7 @@ class UserController extends AdminBaseController ...@@ -66,7 +61,7 @@ class UserController extends AdminBaseController
*/ */
public function store(CreateUserRequest $request) public function store(CreateUserRequest $request)
{ {
$data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]); $data = $this->mergeRequestWithPermissions($request);
$this->user->createWithRoles($data, $request->roles); $this->user->createWithRoles($data, $request->roles);
...@@ -100,7 +95,7 @@ class UserController extends AdminBaseController ...@@ -100,7 +95,7 @@ class UserController extends AdminBaseController
*/ */
public function update($id, UpdateUserRequest $request) public function update($id, UpdateUserRequest $request)
{ {
$data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]); $data = $this->mergeRequestWithPermissions($request);
$this->user->updateAndSyncRoles($id, $data, $request->roles); $this->user->updateAndSyncRoles($id, $data, $request->roles);
...@@ -122,4 +117,4 @@ class UserController extends AdminBaseController ...@@ -122,4 +117,4 @@ class UserController extends AdminBaseController
return Redirect::route('dashboard.user.index'); return Redirect::route('dashboard.user.index');
} }
} }
\ No newline at end of file
...@@ -14,10 +14,6 @@ use Modules\User\Http\Requests\RegisterRequest; ...@@ -14,10 +14,6 @@ use Modules\User\Http\Requests\RegisterRequest;
use Modules\User\Http\Requests\ResetCompleteRequest; use Modules\User\Http\Requests\ResetCompleteRequest;
use Modules\User\Http\Requests\ResetRequest; use Modules\User\Http\Requests\ResetRequest;
/**
* @Controller()
* @Before("auth.guest", on={"getLogin", "getRegister"})
*/
class AuthController class AuthController
{ {
use CommanderTrait; use CommanderTrait;
...@@ -39,7 +35,7 @@ class AuthController ...@@ -39,7 +35,7 @@ class AuthController
]; ];
$remember = (bool)$request->get('remember_me', false); $remember = (bool)$request->get('remember_me', false);
try { try {
if ($user = Sentinel::authenticate($credentials, $remember)) { if (Sentinel::authenticate($credentials, $remember)) {
Flash::success('Successfully logged in.'); Flash::success('Successfully logged in.');
return Redirect::route('dashboard.index', compact('user')); return Redirect::route('dashboard.index', compact('user'));
} }
...@@ -121,4 +117,4 @@ class AuthController ...@@ -121,4 +117,4 @@ class AuthController
return Redirect::route('login'); return Redirect::route('login');
} }
} }
\ No newline at end of file
...@@ -11,4 +11,4 @@ class GuestFilter ...@@ -11,4 +11,4 @@ class GuestFilter
return Redirect::route('dashboard.index'); return Redirect::route('dashboard.index');
} }
} }
} }
\ No newline at end of file
<?php namespace Modules\User\Http\Middleware;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Support\Facades\Redirect;
class GuestMiddleware implements Middleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
dd('ok?');
if (Sentinel::check()) {
return Redirect::route('dashboard.index');
}
}
}
<?php namespace Modules\User\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateRolesRequest extends FormRequest
{
public function rules()
{
return [
'name' => 'required',
'slug' => 'required',
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
\ No newline at end of file
...@@ -23,4 +23,4 @@ class CreateUserRequest extends FormRequest ...@@ -23,4 +23,4 @@ class CreateUserRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -31,4 +31,4 @@ class LoginRequest extends FormRequest ...@@ -31,4 +31,4 @@ class LoginRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -31,4 +31,4 @@ class RegisterRequest extends FormRequest ...@@ -31,4 +31,4 @@ class RegisterRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -31,4 +31,4 @@ class ResetCompleteRequest extends FormRequest ...@@ -31,4 +31,4 @@ class ResetCompleteRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -30,4 +30,4 @@ class ResetRequest extends FormRequest ...@@ -30,4 +30,4 @@ class ResetRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
class UpdateRoleRequest extends FormRequest class RolesRequest extends FormRequest
{ {
public function rules() public function rules()
{ {
...@@ -21,4 +21,4 @@ class UpdateRoleRequest extends FormRequest ...@@ -21,4 +21,4 @@ class UpdateRoleRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -22,4 +22,4 @@ class UpdateUserRequest extends FormRequest ...@@ -22,4 +22,4 @@ class UpdateUserRequest extends FormRequest
{ {
return []; return [];
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
$router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'LaravelLocalizationRedirectFilter|auth.admin|permissions'], function($router) $router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'LaravelLocalizationRedirectFilter|auth.admin|permissions'], function($router)
{ {
$router->group(['prefix' => Config::get('core::core.admin-prefix')], function($router) $router->group(['prefix' => Config::get('core::core.admin-prefix'), 'namespace' => 'Modules\User\Http\Controllers'], function($router)
{ {
$router->resource('users', 'Admin\UserController', ['except' => ['show'], 'names' => [ $router->resource('users', 'Admin\UserController', ['except' => ['show'], 'names' => [
'index' => 'dashboard.user.index', 'index' => 'dashboard.user.index',
...@@ -23,7 +23,7 @@ $router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'Larav ...@@ -23,7 +23,7 @@ $router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'Larav
}); });
}); });
$router->group(['prefix' => 'auth'], function($router) $router->group(['prefix' => 'auth', 'namespace' => 'Modules\User\Http\Controllers'], function($router)
{ {
# Login # Login
$router->get('login', ['before' => 'auth.guest', 'as' => 'login', 'uses' => 'AuthController@getLogin']); $router->get('login', ['before' => 'auth.guest', 'as' => 'login', 'uses' => 'AuthController@getLogin']);
......
<?php namespace Modules\User\Listeners; <?php namespace Modules\User\Listeners;
use Cartalyst\Sentinel\Laravel\Facades\Activation; use Cartalyst\Sentinel\Laravel\Facades\Activation;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Laracasts\Commander\Events\EventListener; use Laracasts\Commander\Events\EventListener;
...@@ -16,7 +17,7 @@ class SendRegistrationConfirmationEmail extends EventListener ...@@ -16,7 +17,7 @@ class SendRegistrationConfirmationEmail extends EventListener
'activationcode' => $activation->code 'activationcode' => $activation->code
]; ];
Mail::queue('session::emails.welcome',$data, Mail::queue('session::emails.welcome',$data,
function ($m) use ($user) { function (Message $m) use ($user) {
$m->to($user->email)->subject('Welcome.'); $m->to($user->email)->subject('Welcome.');
} }
); );
......
<?php namespace Modules\User\Listeners; <?php namespace Modules\User\Listeners;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Laracasts\Commander\Events\EventListener; use Laracasts\Commander\Events\EventListener;
...@@ -10,9 +11,9 @@ class SendResetCodeEmail extends EventListener ...@@ -10,9 +11,9 @@ class SendResetCodeEmail extends EventListener
$user = $event->user; $user = $event->user;
$code = $event->reminder->code; $code = $event->reminder->code;
Mail::queue('SessionModule::emails.reminder', compact('user', 'code'), function($m) use ($user) Mail::queue('SessionModule::emails.reminder', compact('user', 'code'), function(Message $m) use ($user)
{ {
$m->to($user->email)->subject('Reset your account password.'); $m->to($user->email)->subject('Reset your account password.');
}); });
} }
} }
\ No newline at end of file
...@@ -19,4 +19,4 @@ class UserPresenter extends Presenter ...@@ -19,4 +19,4 @@ class UserPresenter extends Presenter
{ {
return $this->first_name . ' ' . $this->last_name; return $this->first_name . ' ' . $this->last_name;
} }
} }
\ No newline at end of file
<?php namespace Modules\User\Providers; <?php namespace Modules\User\Providers;
use Illuminate\Routing\Router; use Illuminate\Routing\Router;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
/** /**
* Called before routes are registered. * The root namespace to assume when generating URLs to actions.
* *
* Register any model bindings or pattern based filters. * @var string
* */
* @param Router $router protected $rootUrlNamespace = 'Modules\User\Http\Controllers';
* @param UrlGenerator $url
* @return void /**
*/ * The controllers to scan for route annotations.
public function before(Router $router, UrlGenerator $url) *
{ * @var array
$url->setRootControllerNamespace('Modules\User\Http\Controllers'); */
} protected $scan = [
'Modules\User\Http\Controllers',
];
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @param Router $router
* @return void
*/
public function before(Router $router)
{
//
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map(Router $router)
{
require __DIR__ . '/../Http/routes.php';
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->app->booted(function()
{
$this->namespaced('Modules\User\Http\Controllers', function(Router $router)
{
require __DIR__ . '/../Http/routes.php';
});
});
}
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
use Illuminate\Routing\Router; use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Modules\User\Events\RegisterSidebarMenuItemEvent;
class UserServiceProvider extends ServiceProvider class UserServiceProvider extends ServiceProvider
{ {
...@@ -26,6 +25,11 @@ class UserServiceProvider extends ServiceProvider ...@@ -26,6 +25,11 @@ class UserServiceProvider extends ServiceProvider
'auth.guest' => 'GuestFilter' 'auth.guest' => 'GuestFilter'
] ]
]; ];
protected $middleware = [
'User' => [
'auth.guest' => 'GuestFilter'
]
];
/** /**
* Register the service provider. * Register the service provider.
...@@ -36,8 +40,8 @@ class UserServiceProvider extends ServiceProvider ...@@ -36,8 +40,8 @@ class UserServiceProvider extends ServiceProvider
{ {
$this->app->booted(function ($app) { $this->app->booted(function ($app) {
$this->registerFilters($app['router']); $this->registerFilters($app['router']);
$this->registerMiddleware($app['router']);
$this->registerBindings(); $this->registerBindings();
$this->registerEvents($app['events']);
}); });
} }
...@@ -80,7 +84,14 @@ class UserServiceProvider extends ServiceProvider ...@@ -80,7 +84,14 @@ class UserServiceProvider extends ServiceProvider
); );
} }
private function registerEvents($events) private function registerMiddleware($router)
{ {
foreach ($this->middleware as $module => $middlewares) {
foreach ($middlewares as $name => $middleware) {
$class = "Modules\\{$module}\\Http\\Middleware\\{$middleware}";
$router->middleware($name, $class);
}
}
} }
} }
...@@ -39,4 +39,4 @@ interface RoleRepository ...@@ -39,4 +39,4 @@ interface RoleRepository
* @return mixed * @return mixed
*/ */
public function delete($id); public function delete($id);
} }
\ No newline at end of file
...@@ -69,4 +69,4 @@ class SentinelRoleRepository implements RoleRepository ...@@ -69,4 +69,4 @@ class SentinelRoleRepository implements RoleRepository
return $role->delete(); return $role->delete();
} }
} }
\ No newline at end of file
...@@ -36,7 +36,7 @@ class SentinelUserRepository implements UserRepository ...@@ -36,7 +36,7 @@ class SentinelUserRepository implements UserRepository
* @param $data * @param $data
* @return mixed * @return mixed
*/ */
public function create($data) public function create(array $data)
{ {
return $this->user->create((array) $data); return $this->user->create((array) $data);
} }
...@@ -113,4 +113,4 @@ class SentinelUserRepository implements UserRepository ...@@ -113,4 +113,4 @@ class SentinelUserRepository implements UserRepository
throw new UserNotFoundException; throw new UserNotFoundException;
} }
} }
\ No newline at end of file
...@@ -14,9 +14,10 @@ interface UserRepository ...@@ -14,9 +14,10 @@ interface UserRepository
/** /**
* Create a user resource * Create a user resource
* @param array $data
* @return mixed * @return mixed
*/ */
public function create($data); public function create(array $data);
/** /**
* Create a user and assign roles to it * Create a user and assign roles to it
...@@ -56,4 +57,4 @@ interface UserRepository ...@@ -56,4 +57,4 @@ interface UserRepository
* @return mixed * @return mixed
*/ */
public function delete($id); public function delete($id);
} }
\ No newline at end of file
...@@ -34,4 +34,4 @@ return [ ...@@ -34,4 +34,4 @@ return [
'email' => 'Email', 'email' => 'Email',
'actions' => 'Actions', 'actions' => 'Actions',
] ]
]; ];
\ No newline at end of file
...@@ -5,4 +5,4 @@ return [ ...@@ -5,4 +5,4 @@ return [
'delete' => 'Suprimmer', 'delete' => 'Suprimmer',
'create' => 'Créer', 'create' => 'Créer',
'update' => 'Mise à jour', 'update' => 'Mise à jour',
]; ];
\ No newline at end of file
...@@ -34,4 +34,4 @@ return [ ...@@ -34,4 +34,4 @@ return [
'email' => 'Email', 'email' => 'Email',
'actions' => 'Actions', 'actions' => 'Actions',
] ]
]; ];
\ No newline at end of file
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<?php foreach($permissionName as $permissionAction): ?> <?php foreach($permissionName as $permissionAction): ?>
<div class="checkbox"> <div class="checkbox">
<label for="<?php echo "$subPermissionTitle.$permissionAction" ?>"> <label for="<?php echo "$subPermissionTitle.$permissionAction" ?>">
<input id="<?php echo "$subPermissionTitle.$permissionAction" ?>" name="permissions[<?php echo "$subPermissionTitle.$permissionAction" ?>]" type="checkbox" class="flat-blue" <?php echo $user->hasAccess("$subPermissionTitle.$permissionAction") ? 'checked' : '' ?> value="true" /> {{ ucfirst($permissionAction) }} <input id="<?php echo "$subPermissionTitle.$permissionAction" ?>" name="permissions[<?php echo "$subPermissionTitle.$permissionAction" ?>]" type="checkbox" class="flat-blue" <?php echo $model->hasAccess("$subPermissionTitle.$permissionAction") ? 'checked' : '' ?> value="true" /> {{ ucfirst($permissionAction) }}
</label> </label>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
@stop @stop
@section('styles') @section('styles')
<link href="{{{ core_asset('css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" />
@stop @stop
@section('content') @section('content')
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
</div> </div>
</div> </div>
<div class="tab-pane" id="tab_2-2"> <div class="tab-pane" id="tab_2-2">
@include('user::admin.roles.partials.permissions-create') @include('user::admin.partials.permissions-create')
</div> </div>
<div class="box-footer"> <div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('user::button.create') }}</button> <button type="submit" class="btn btn-primary btn-flat">{{ trans('user::button.create') }}</button>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
@stop @stop
@section('styles') @section('styles')
<link href="{{{ core_asset('css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" />
@stop @stop
@section('content') @section('content')
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</div> </div>
</div><!-- /.tab-pane --> </div><!-- /.tab-pane -->
<div class="tab-pane" id="tab_2-2"> <div class="tab-pane" id="tab_2-2">
@include('user::admin.roles.partials.permissions') @include('user::admin.partials.permissions', ['model' => $role])
</div><!-- /.tab-pane --> </div><!-- /.tab-pane -->
<div class="tab-pane" id="tab_3-3"> <div class="tab-pane" id="tab_3-3">
<div class="box-body"> <div class="box-body">
...@@ -88,4 +88,4 @@ $( document ).ready(function() { ...@@ -88,4 +88,4 @@ $( document ).ready(function() {
}); });
}); });
</script> </script>
@stop @stop
\ No newline at end of file
<div class="box-body">
<div class="row">
<div class="col-md-12">
<?php foreach($permissions as $name => $value): ?>
<h3>{{ $name }} Module</h3>
<?php foreach($value as $subPermissionTitle => $permissionName): ?>
<h4>{{ ucfirst($subPermissionTitle) }}</h4>
<?php foreach($permissionName as $permissionAction): ?>
<div class="checkbox">
<label for="<?php echo "$subPermissionTitle.$permissionAction" ?>">
<input id="<?php echo "$subPermissionTitle.$permissionAction" ?>" name="permissions[<?php echo "$subPermissionTitle.$permissionAction" ?>]" type="checkbox" class="flat-blue" value="true" /> {{ ucfirst($permissionAction) }}
</label>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
</div>
</div>
\ No newline at end of file
<div class="box-body">
<div class="row">
<div class="col-md-12">
<?php foreach($permissions as $name => $value): ?>
<h3>{{ $name }} Module</h3>
<?php foreach($value as $subPermissionTitle => $permissionName): ?>
<h4>{{ ucfirst($subPermissionTitle) }}</h4>
<?php foreach($permissionName as $permissionAction): ?>
<div class="checkbox">
<label for="<?php echo "$subPermissionTitle.$permissionAction" ?>">
<input id="<?php echo "$subPermissionTitle.$permissionAction" ?>" name="permissions[<?php echo "$subPermissionTitle.$permissionAction" ?>]" type="checkbox" class="flat-blue" <?php echo $role->hasAccess("$subPermissionTitle.$permissionAction") ? 'checked' : '' ?> value="true" /> {{ ucfirst($permissionAction) }}
</label>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
</div>
</div>
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
@stop @stop
@section('styles') @section('styles')
<link href="{{{ core_asset('css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" />
@stop @stop
@section('content') @section('content')
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
</div> </div>
<div class="tab-pane" id="tab_3-3"> <div class="tab-pane" id="tab_3-3">
<div class="box-body"> <div class="box-body">
@include('user::admin.users.partials.permissions-create') @include('user::admin.partials.permissions-create')
</div> </div>
</div> </div>
<div class="box-footer"> <div class="box-footer">
...@@ -114,4 +114,4 @@ $( document ).ready(function() { ...@@ -114,4 +114,4 @@ $( document ).ready(function() {
}); });
}); });
</script> </script>
@stop @stop
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
@stop @stop
@section('styles') @section('styles')
<link href="{{{ core_asset('css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" />
@stop @stop
@section('content') @section('content')
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
</div> </div>
<div class="tab-pane" id="tab_3-3"> <div class="tab-pane" id="tab_3-3">
<div class="box-body"> <div class="box-body">
@include('user::admin.users.partials.permissions') @include('user::admin.partials.permissions', ['model' => $user])
</div> </div>
</div> </div>
<div class="box-footer"> <div class="box-footer">
...@@ -95,4 +95,4 @@ $( document ).ready(function() { ...@@ -95,4 +95,4 @@ $( document ).ready(function() {
}); });
}); });
</script> </script>
@stop @stop
\ No newline at end of file
...@@ -105,4 +105,4 @@ background-color: #f6f6f6; ...@@ -105,4 +105,4 @@ background-color: #f6f6f6;
</table> </table>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
</title> </title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'> <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- bootstrap 3.0.2 --> <!-- bootstrap 3.0.2 -->
<link href="{{{ core_asset('css/vendor/bootstrap.min.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/bootstrap.min.css') }}}" rel="stylesheet" type="text/css" />
<!-- font Awesome --> <!-- font Awesome -->
<link href="{{{ core_asset('css/vendor/font-awesome.min.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/font-awesome.min.css') }}}" rel="stylesheet" type="text/css" />
<!-- Ionicons --> <!-- Ionicons -->
<link href="{{{ core_asset('css/vendor/ionicons.min.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/ionicons.min.css') }}}" rel="stylesheet" type="text/css" />
<!-- Theme style --> <!-- Theme style -->
<link href="{{{ core_asset('css/AdminLTE.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/AdminLTE.css') }}}" rel="stylesheet" type="text/css" />
<link href="{{{ core_asset('css/vendor/alertify/alertify.core.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/alertify/alertify.core.css') }}}" rel="stylesheet" type="text/css" />
<link href="{{{ core_asset('css/vendor/alertify/alertify.default.css') }}}" rel="stylesheet" type="text/css" /> <link href="{{{ Module::asset('core', 'css/vendor/alertify/alertify.default.css') }}}" rel="stylesheet" type="text/css" />
<script src="{{{ core_asset('js/vendor/jquery.min.js') }}}"></script> <script src="{{{ Module::asset('core', 'js/vendor/jquery.min.js') }}}"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</div> </div>
<!-- Bootstrap --> <!-- Bootstrap -->
<script src="{{{ core_asset('js/vendor/bootstrap.min.js') }}}" type="text/javascript"></script> <script src="{{{ Module::asset('core', 'js/vendor/bootstrap.min.js') }}}" type="text/javascript"></script>
<script src="{{{ core_asset('js/vendor/alertify/alertify.js') }}}" type="text/javascript"></script> <script src="{{{ Module::asset('core', 'js/vendor/alertify/alertify.js') }}}" type="text/javascript"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -31,4 +31,4 @@ Login | @parent ...@@ -31,4 +31,4 @@ Login | @parent
</div> </div>
</form> </form>
@stop @stop
\ No newline at end of file
...@@ -29,4 +29,4 @@ Register | @parent ...@@ -29,4 +29,4 @@ Register | @parent
<a href="{{ URL::route('login') }}" class="text-center">I already have a membership</a> <a href="{{ URL::route('login') }}" class="text-center">I already have a membership</a>
</div> </div>
{!! Form::close() !!} {!! Form::close() !!}
@stop @stop
\ No newline at end of file
...@@ -21,4 +21,4 @@ Reset password | @parent ...@@ -21,4 +21,4 @@ Reset password | @parent
</div> </div>
{!! Form::close(); !!} {!! Form::close(); !!}
@stop @stop
\ No newline at end of file
...@@ -25,4 +25,4 @@ Reset password | @parent ...@@ -25,4 +25,4 @@ Reset password | @parent
</div> </div>
{!! Form::close(); !!} {!! Form::close(); !!}
@stop @stop
\ No newline at end of file
...@@ -2,38 +2,26 @@ ...@@ -2,38 +2,26 @@
use Cartalyst\Sentinel\Laravel\Facades\Sentinel; use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use TestCase; use Modules\Core\Tests\BaseTestCase;
class SessionUrlTest extends TestCase class SessionUrlTest extends BaseTestCase
{ {
/** @test */ /** @test */
public function loginPageShouldBeAccessible() public function loginPageShouldBeAccessible()
{ {
$crawler = $this->client->request('GET', '/auth/login'); $this->checkResponseIsOkAndContains(['GET', '/auth/login'], '.header:contains("Sign In")');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('.header:contains("Sign In")'));
} }
/** @test */ /** @test */
public function registerPageShouldBeAccessible() public function registerPageShouldBeAccessible()
{ {
$crawler = $this->client->request('GET', '/auth/register'); $this->checkResponseIsOkAndContains(['GET', '/auth/register'], '.header:contains("Register New Membership")');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('.header:contains("Register New Membership")'));
} }
/** @test */ /** @test */
public function forgotPasswordShouldBeAccessible() public function forgotPasswordShouldBeAccessible()
{ {
$crawler = $this->client->request('GET', '/auth/reset'); $this->checkResponseIsOkAndContains(['GET', '/auth/reset'], '.header:contains("Reset Password")');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('.header:contains("Reset Password")'));
} }
/** @test */ /** @test */
...@@ -42,7 +30,7 @@ class SessionUrlTest extends TestCase ...@@ -42,7 +30,7 @@ class SessionUrlTest extends TestCase
$this->app['router']->enableFilters(); $this->app['router']->enableFilters();
Sentinel::logout(); Sentinel::logout();
$crawler = $this->client->request('GET', '/' . Config::get('core::core.admin-prefix')); $this->client->request('GET', '/' . Config::get('core::core.admin-prefix'));
$this->assertRedirectedTo('auth/login'); $this->assertRedirectedTo('auth/login');
} }
...@@ -56,9 +44,7 @@ class SessionUrlTest extends TestCase ...@@ -56,9 +44,7 @@ class SessionUrlTest extends TestCase
$user = Sentinel::findById(4); $user = Sentinel::findById(4);
Sentinel::login($user); Sentinel::login($user);
$crawler = $this->client->request('GET', '/' . Config::get('core::core.admin-prefix')); $this->checkResponseIsOkAndContains(['GET', '/' . Config::get('core::core.admin-prefix')], 'h1:contains("Dashboard")');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Dashboard")'));
} }
}
\ No newline at end of file }
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
use Cartalyst\Sentinel\Laravel\Facades\Sentinel; use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Modules\Core\Tests\BaseTestCase;
class UserUrlTest extends \TestCase class UserUrlTest extends BaseTestCase
{ {
public function setUp() public function setUp()
{ {
...@@ -17,11 +18,8 @@ class UserUrlTest extends \TestCase ...@@ -17,11 +18,8 @@ class UserUrlTest extends \TestCase
public function userIndexShouldBeAccessible() public function userIndexShouldBeAccessible()
{ {
$uri = '/' . Config::get('core::core.admin-prefix') . '/users'; $uri = '/' . Config::get('core::core.admin-prefix') . '/users';
$crawler = $this->client->request('GET', $uri);
$this->assertTrue($this->client->getResponse()->isOk()); $this->checkResponseIsOkAndContains(['GET', $uri], 'h1:contains("Users")');
$this->assertCount(1, $crawler->filter('h1:contains("Users")'));
} }
...@@ -29,54 +27,39 @@ class UserUrlTest extends \TestCase ...@@ -29,54 +27,39 @@ class UserUrlTest extends \TestCase
public function userEditShouldBeAccessible() public function userEditShouldBeAccessible()
{ {
$uri = '/' . Config::get('core::core.admin-prefix') . '/users/4/edit'; $uri = '/' . Config::get('core::core.admin-prefix') . '/users/4/edit';
$crawler = $this->client->request('GET', $uri);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Edit User")')); $this->checkResponseIsOkAndContains(['GET', $uri], 'h1:contains("Edit User")');
} }
/** @test */ /** @test */
public function userCreateShouldBeAccessible() public function userCreateShouldBeAccessible()
{ {
$uri = '/' . Config::get('core::core.admin-prefix') . '/users/create'; $uri = '/' . Config::get('core::core.admin-prefix') . '/users/create';
$crawler = $this->client->request('GET', $uri);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("New User")')); $this->checkResponseIsOkAndContains(['GET', $uri], 'h1:contains("New User")');
} }
/** @test */ /** @test */
public function roleIndexShouldBeAccessible() public function roleIndexShouldBeAccessible()
{ {
$uri = '/' . Config::get('core::core.admin-prefix') . '/roles'; $uri = '/' . Config::get('core::core.admin-prefix') . '/roles';
$crawler = $this->client->request('GET', $uri);
$this->assertTrue($this->client->getResponse()->isOk()); $this->checkResponseIsOkAndContains(['GET', $uri], 'h1:contains("Roles")');
$this->assertCount(1, $crawler->filter('h1:contains("Roles")'));
} }
/** @test */ /** @test */
public function roleCreateShouldBeAccessible() public function roleCreateShouldBeAccessible()
{ {
$uri = '/' . Config::get('core::core.admin-prefix') . '/roles/create'; $uri = '/' . Config::get('core::core.admin-prefix') . '/roles/create';
$crawler = $this->client->request('GET', $uri);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("New Role")')); $this->checkResponseIsOkAndContains(['GET', $uri], 'h1:contains("New Role")');
} }
/** @test */ /** @test */
public function roleEditShouldBeAccessible() public function roleEditShouldBeAccessible()
{ {
$uri = '/' . Config::get('core::core.admin-prefix') . '/roles/6/edit'; $uri = '/' . Config::get('core::core.admin-prefix') . '/roles/6/edit';
$crawler = $this->client->request('GET', $uri);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Updating Role")')); $this->checkResponseIsOkAndContains(['GET', $uri], 'h1:contains("Updating Role")');
} }
} }
...@@ -3,10 +3,8 @@ use Cartalyst\Sentinel\Laravel\Facades\Sentinel; ...@@ -3,10 +3,8 @@ use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
View::composer('core::partials.sidebar-nav', 'Modules\User\Composers\SidebarViewComposer'); View::composer('core::partials.sidebar-nav', 'Modules\User\Composers\SidebarViewComposer');
View::composer([ View::composer([
'user::admin.roles.partials.permissions', 'user::admin.partials.permissions',
'user::admin.roles.partials.permissions-create', 'user::admin.partials.permissions-create',
'user::admin.users.partials.permissions',
'user::admin.users.partials.permissions-create',
], 'Modules\User\Composers\PermissionsViewComposer'); ], 'Modules\User\Composers\PermissionsViewComposer');
View::composer(['core::partials.sidebar-nav', 'core::partials.top-nav'], function($view) View::composer(['core::partials.sidebar-nav', 'core::partials.top-nav'], function($view)
......
<?php
if (!function_exists('user_asset')) {
function user_asset($url, array $attributes = [], $secure = false)
{
return Module::asset('user', $url, $attributes, $secure);
}
}
\ No newline at end of file
<?php <?php
Event::listen('Modules.User.Events.*', 'Modules\User\Listeners\SendResetCodeEmail'); Event::listen('Modules.User.Events.*', 'Modules\User\Listeners\SendResetCodeEmail');
Event::listen('Modules.User.Events.*', 'Modules\User\Listeners\SendRegistrationConfirmationEmail'); Event::listen('Modules.User.Events.*', 'Modules\User\Listeners\SendRegistrationConfirmationEmail');
\ No newline at end of file
# User module # User module
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/304d1d01-3347-4958-915f-b2daabfe5f5a/mini.png)](https://insight.sensiolabs.com/projects/304d1d01-3347-4958-915f-b2daabfe5f5a)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nWidart-Modules/User/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nWidart-Modules/User/?branch=master)
This module is responsible for handling the users and roles. This module is responsible for handling the users and roles.
## Installation ## Installation
This module is loading the the [Pingpong-labs/module](https://github.com/pingpong-labs/modules) package. One way of installing it, is with the `php artisan module:install nWidart-Modules/User` command. This module is loading the the [Pingpong-labs/module](https://github.com/pingpong-labs/modules) package. One way of installing it, is with the `php artisan module:install nWidart-Modules/User` command.
### Module dependencies
This module depends on the [Session module](https://github.com/nWidart-Modules/Session).
\ No newline at end of file
...@@ -18,5 +18,4 @@ Config::addNamespace('user', __DIR__ . '/Config/'); ...@@ -18,5 +18,4 @@ Config::addNamespace('user', __DIR__ . '/Config/');
require __DIR__ . '/composers.php'; require __DIR__ . '/composers.php';
require __DIR__ . '/helpers.php'; require __DIR__ . '/listeners.php';
require __DIR__ . '/listeners.php';
\ No newline at end of file
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