Commit aedb3fe5 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/User/' changes from f048f16..5b82381

5b82381 Add the permission to the settings page
7ecbdd1 Fix typo
36ca7c5 Translating the role management messages
b3d88ed Translate the user management messages
b872e7c Translate authentication messages
ca5de39 Translating the datatables script
506fc80 Change to blue button
60557d2 Merge pull request #17 from AsgardCms/fix-sentry-implementation
c3b9c1c Use new translated key
ca4234f Remove the slug as required
5d39ede Set the user created in admin to activated
4e10cf8 Fix the update and sync roles method
7273e09 Fix the user update method
e72454f Implement the hasRole method for sentry

git-subtree-dir: Modules/User
git-subtree-split: 5b823810cefcb9049888920b7e40fde4f7283bd9
parent f4edb764
......@@ -83,6 +83,8 @@ class SentinelGroupSeedTableSeeder extends Seeder
'media.edit' => true,
'media.update' => true,
'media.destroy' => true,
/* Settings */
'settings.index' => true,
];
$group->save();
......
......@@ -66,6 +66,8 @@ class SentryGroupSeedTableSeeder extends Seeder
'media.edit' => 1,
'media.update' => 1,
'media.destroy' => 1,
/* Settings */
'settings.index' => 1,
],
));
......
<?php namespace Modules\User\Entities\Sentry;
use Cartalyst\Sentry\Facades\Laravel\Sentry;
use Cartalyst\Sentry\Users\Eloquent\User as SentryModel;
use Laracasts\Presenter\PresentableTrait;
use Modules\User\Entities\UserInterface;
......@@ -30,5 +31,8 @@ class User extends SentryModel implements UserInterface
*/
public function hasRole($roleId)
{
$role = Sentry::findGroupById($roleId);
return $this->inGroup($role);
}
}
......@@ -56,7 +56,7 @@ class RolesController extends BaseUserModuleController
$this->role->create($data);
Flash::success('Role created');
Flash::success(trans('user::messages.role created'));
return Redirect::route('dashboard.role.index');
}
......@@ -69,6 +69,7 @@ class RolesController extends BaseUserModuleController
public function edit($id)
{
if (!$role = $this->role->find($id)) {
Flash::error(trans('user::messages.role not found'));
return Redirect::to('user::admin.roles.index');
}
......@@ -88,7 +89,7 @@ class RolesController extends BaseUserModuleController
$this->role->update($id, $data);
Flash::success('Role updated!');
Flash::success(trans('user::messages.role updated'));
return Redirect::route('dashboard.role.index');
}
......@@ -102,7 +103,7 @@ class RolesController extends BaseUserModuleController
{
$this->role->delete($id);
Flash::success('Role deleted!');
Flash::success(trans('user::messages.role deleted'));
return Redirect::route('dashboard.role.index');
}
......
......@@ -75,9 +75,9 @@ class UserController extends BaseUserModuleController
{
$data = $this->mergeRequestWithPermissions($request);
$this->user->createWithRoles($data, $request->roles);
$this->user->createWithRoles($data, $request->roles, true);
Flash::success('User created.');
Flash::success(trans('user::messages.user created'));
return Redirect::route('dashboard.user.index');
}
......@@ -90,7 +90,7 @@ class UserController extends BaseUserModuleController
public function edit($id)
{
if (!$user = $this->user->find($id)) {
Flash::error('User not found');
Flash::error(trans('user::messages.user not found'));
return Redirect::route('dashboard.user.index');
}
$roles = $this->role->all();
......@@ -111,7 +111,7 @@ class UserController extends BaseUserModuleController
$this->user->updateAndSyncRoles($id, $data, $request->roles);
Flash::success('User updated.');
Flash::success(trans('user::messages.user updated'));
return Redirect::route('dashboard.user.index');
}
......@@ -125,7 +125,7 @@ class UserController extends BaseUserModuleController
{
$this->user->delete($id);
Flash::success('User deleted');
Flash::success(trans('user::messages.user deleted'));
return Redirect::route('dashboard.user.index');
}
......
......@@ -41,7 +41,7 @@ class AuthController
$error = $this->auth->login($credentials, $remember);
if (!$error) {
Flash::success('Successfully logged in.');
Flash::success(trans('user::messages.successfully logged in'));
return Redirect::intended('/');
}
......@@ -58,7 +58,7 @@ class AuthController
{
$this->execute('Modules\User\Commands\RegisterNewUserCommand', $request->all());
Flash::success('Account created. Please check your email to activate your account.');
Flash::success(trans('user::messages.account created check email for activation'));
return Redirect::route('register');
}
......@@ -73,10 +73,10 @@ class AuthController
public function getActivate($userId, $code)
{
if ($this->auth->activate($userId, $code)) {
Flash::success('Account activated. You can now login.');
Flash::success(trans('user::messages.account activated you can now login'));
return Redirect::route('login');
}
Flash::error('There was an error with the activation.');
Flash::error(lang('user::messages.there was an error with the activation'));
return Redirect::route('register');
}
......@@ -90,13 +90,12 @@ class AuthController
try {
$this->execute('Modules\User\Commands\BeginResetProcessCommand', $request->all());
} catch (UserNotFoundException $e) {
Flash::error('No user with that email address belongs in our system.');
Flash::error(trans('user::messages.no user found'));
return Redirect::back()->withInput();
}
Flash::success('Check your email to reset your password.');
Flash::success(trans('user::messages.check email to reset password'));
return Redirect::route('reset');
}
......@@ -113,14 +112,14 @@ class AuthController
array_merge($request->all(), ['userId' => $userId, 'code' => $code])
);
} catch (UserNotFoundException $e) {
Flash::error('The user no longer exists.');
Flash::error(trans('user::messages.user no longer exists'));
return Redirect::back()->withInput();
} catch (InvalidOrExpiredResetCode $e) {
Flash::error('Invalid or expired reset code.');
Flash::error(trans('user::messages.invalid reset code'));
return Redirect::back()->withInput();
}
Flash::success('Password has been reset. You can now login with your new password.');
Flash::success(trans('user::messages.password reset'));
return Redirect::route('login');
}
}
......@@ -8,7 +8,6 @@ class RolesRequest extends FormRequest
{
return [
'name' => 'required',
'slug' => 'required',
];
}
......
......@@ -74,12 +74,28 @@ class SentryUserRepository implements UserRepository
public function updateAndSyncRoles($userId, $data, $roles)
{
$user = Sentry::findUserById($userId);
$user = $user->update($data);
$user->save();
$user->update($data);
if (!empty($roles)) {
$adminGroup = Sentry::findGroupByName($roles);
$user->removeGroup();
$user->addGroup($adminGroup);
// Get the user roles
$userRoles = $user->groups()->get()->toArray();
$cleanedRoles = [];
foreach ($userRoles as $role) {
$cleanedRoles[$role['id']] = $role;
}
// Set the new roles
foreach ($roles as $roleId) {
if (isset($cleanedRoles[$roleId])) {
unset($cleanedRoles[$roleId]);
}
$group = Sentry::findGroupById($roleId);
$user->addGroup($group);
}
// Unset the unchecked roles
foreach ($cleanedRoles as $roleId => $role) {
$group = Sentry::findGroupById($roleId);
$user->removeGroup($group);
}
}
}
......
<?php
return [
/* Authentication */
'successfully logged in' => 'Successfully logged in',
'account created check email for activation' => 'Account created. Please check your email to activate your account.',
'account activated you can now login' => 'Account activated. You can now login.',
'there was an error with the activation' => 'There was an error with the activation.',
'no user found' => 'No user with that email address belongs in our system.',
'check email to reset password' => 'Check your email to reset your password.',
'user no longer exists' => 'The user no longer exists.',
'invalid reset code' => 'Invalid or expired reset code.',
'password reset' => 'Password has been reset. You can now login with your new password.',
/* User management */
'user created' => 'User successfully created.',
'user not found' => 'User not found.',
'user updated' => 'User successfully updated.',
'user deleted' => 'User successfully deleted.',
/* Role management */
'role created' => 'Role successfully created.',
'role not found' => 'Role not found.',
'role updated' => 'Role successfully updated.',
'role deleted' => 'Role successfully deleted.',
];
<?php
return [
/* Authentication */
'successfully logged in' => 'Authentification réussie',
'account created check email for activation' => 'Compte créer. Contrôller vos emails pour activer votre compte.',
'account activated you can now login' => 'Compte activer. Vous pouvez désaprésent vous authentifier.',
'there was an error with the activation' => 'Une erreur s\'est produite pendant l\'activation',
'no user found' => 'Aucun utilisateur ne correspond a cette addresse email.',
'check email to reset password' => 'Contrôller vos emails pour réinitialiser votre mot de passe.',
'user no longer exists' => 'Cet utilisateur n\'existe plus.',
'invalid reset code' => 'Code de réinitialisation non valide ou expirer.',
'password reset' => 'Mot de passe réinitialiser. Vous pouvez vous authentifier avec votre nouveau mot de passe.',
/* User management */
'user created' => 'Utilisateur créer.',
'user not found' => 'Utilisateur non trouvé.',
'user updated' => 'Utilisateur mit à jour.',
'user deleted' => 'Utilisateur suprimer',
/* Role management */
'role created' => 'Role créer.',
'role not found' => 'Role non trouvé.',
'role updated' => 'Role mit à jour.',
'role deleted' => 'Role suprimer',
];
......@@ -84,7 +84,7 @@
<h4 class="modal-title" id="myModalLabel">{{ trans('core::core.modal.title') }}</h4>
</div>
<div class="modal-body">
{{ trans('user::users.modal.confirmation-message') }}
{{ trans('core::core.modal.confirmation-message') }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('core::core.button.cancel') }}</button>
......@@ -100,19 +100,24 @@
@stop
@section('scripts')
<?php $locale = App::getLocale(); ?>
<script type="text/javascript">
$(function () {
$('.data-table').dataTable({
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"aoColumns": [
"paginate": true,
"lengthChange": true,
"filter": true,
"sort": true,
"info": true,
"autoWidth": true,
"order": [[ 0, "desc" ]],
"language": {
"url": '<?php echo Module::asset("core:js/vendor/datatables/{$locale}.json") ?>'
},
"columns": [
null,
null,
{ "bSortable": false }
{ "sortable": false }
]
});
});
......
......@@ -100,7 +100,7 @@
<h4 class="modal-title" id="myModalLabel">{{ trans('core::core.modal.title') }}</h4>
</div>
<div class="modal-body">
{{ trans('user::users.modal.confirmation-message') }}
{{ trans('core::core.modal.confirmation-message') }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('core::core.button.cancel') }}</button>
......@@ -116,21 +116,26 @@
@stop
@section('scripts')
<?php $locale = App::getLocale(); ?>
<script type="text/javascript">
$(function () {
$('.data-table').dataTable({
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"aoColumns": [
"paginate": true,
"lengthChange": true,
"filter": true,
"sort": true,
"info": true,
"autoWidth": true,
"order": [[ 0, "desc" ]],
"language": {
"url": '<?php echo Module::asset("core:js/vendor/datatables/{$locale}.json") ?>'
},
"columns": [
null,
null,
null,
null,
{ "bSortable": false }
{ "sortable": false }
]
});
});
......
......@@ -25,7 +25,7 @@ Login | @parent
</div>
</div>
<div class="footer">
<button type="submit" class="btn bg-olive btn-block">Sign me in</button>
<button type="submit" class="btn btn-info btn-block">Sign me in</button>
<p><a href="{{URL::route('reset')}}">I forgot my password</a></p>
<a href="{{URL::route('register')}}" class="text-center">Register a new membership</a>
</div>
......
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