FEATURE #1359: add status changing (user management)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: michal
|
||||
* Date: 24.1.16
|
||||
* Time: 23:20
|
||||
*/
|
||||
|
||||
namespace App\Enumerations;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserStates
|
||||
{
|
||||
/**
|
||||
* Getter for states
|
||||
*
|
||||
* This method returns only list of roles as inserted into database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSimple()
|
||||
{
|
||||
return array_values(self::getWithTranslations());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for states with translations
|
||||
*
|
||||
* This method returns all user states as keys. Values are strings used for translations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getWithTranslations()
|
||||
{
|
||||
return [
|
||||
User::STATE_DELETED => 'admin/userManagement.status_' . User::STATE_DELETED,
|
||||
User::STATE_BLOCKED => 'admin/userManagement.status_' . User::STATE_BLOCKED,
|
||||
User::STATE_ACTIVE => 'admin/userManagement.status_' . User::STATE_ACTIVE
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\UserRoles;
|
||||
use App\Enumerations\UserStates;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Requests\EditUserRequest;
|
||||
@@ -19,12 +20,20 @@ class EditUser extends Controller
|
||||
$id = Auth::user()->id;
|
||||
}
|
||||
|
||||
// try to find given user
|
||||
$user = User::findOrFail($id);
|
||||
// @todo add some authorization (e.g. via can/cannot methods)
|
||||
|
||||
// try to find given user
|
||||
$user = User::where('status', '!=', User::STATE_DELETED)
|
||||
->findOrFail($id);
|
||||
|
||||
$states = UserStates::getWithTranslations();
|
||||
$roles = UserRoles::getWithTranslations();
|
||||
|
||||
return view('admin.userManagement.edit', ['user' => $user, 'roles' => $roles]);
|
||||
return view('admin.userManagement.edit', [
|
||||
'user' => $user,
|
||||
'states' => $states,
|
||||
'roles' => $roles
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,6 +61,10 @@ class EditUser extends Controller
|
||||
$user->role = $request->role;
|
||||
}
|
||||
|
||||
if (isset($request->status)) {
|
||||
$user->status = $request->status;
|
||||
}
|
||||
|
||||
if (isset($request->password)) {
|
||||
$user->password = Hash::make($request->password);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\UserRoles;
|
||||
use App\Enumerations\UserStates;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Models\User;
|
||||
@@ -21,7 +22,12 @@ class UserDetail extends Controller
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
$roles = UserRoles::getWithTranslations();
|
||||
$states = UserStates::getWithTranslations();
|
||||
|
||||
return view('admin.userManagement.detail', ['user' => $user, 'roles' => $roles]);
|
||||
return view('admin.userManagement.detail', [
|
||||
'user' => $user,
|
||||
'states' => $states,
|
||||
'roles' => $roles
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,28 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'addNewUser' => 'Add new user',
|
||||
'name' => 'Full name',
|
||||
'email' => 'Email',
|
||||
'password' => 'Password',
|
||||
'roles' => 'Please, select user\'s role',
|
||||
'role_admin' => 'Admin',
|
||||
'role_editor' => 'Editor',
|
||||
'role_visitor' => 'Visitor',
|
||||
'register' => 'Create user',
|
||||
'addNewUser' => 'Add new user',
|
||||
'name' => 'Full name',
|
||||
'email' => 'Email',
|
||||
'password' => 'Password',
|
||||
'roles' => 'Please, select user\'s role',
|
||||
'role_admin' => 'Admin',
|
||||
'role_editor' => 'Editor',
|
||||
'role_visitor' => 'Visitor',
|
||||
'status' => 'Status',
|
||||
'status_deleted' => 'Deleted',
|
||||
'status_blocked' => 'Blocked',
|
||||
'status_active' => 'Active',
|
||||
'register' => 'Create user',
|
||||
'registrationSuccessfull' => 'New user successfully added.',
|
||||
'profile' => 'Your profile',
|
||||
'overview' => 'List of all users',
|
||||
'noUsers' => 'No users avialable.',
|
||||
'detail' => 'Details of user :name (:email)',
|
||||
'editUser' => 'Editing user :name (:email)',
|
||||
'usersActions' => 'User\'s actions',
|
||||
'update' => 'Update informations',
|
||||
'passwordLeaveEmpty' => 'Leave empty, if you do not want to change it.',
|
||||
'userSuccessfullyEdited' => 'User successfully edited.',
|
||||
'profile' => 'Your profile',
|
||||
'overview' => 'List of all users',
|
||||
'noUsers' => 'No users avialable.',
|
||||
'detail' => 'Details of user :name (:email)',
|
||||
'editUser' => 'Editing user :name (:email)',
|
||||
'usersActions' => 'User\'s actions',
|
||||
'update' => 'Update informations',
|
||||
'passwordLeaveEmpty' => 'Leave empty, if you do not want to change it.',
|
||||
'userSuccessfullyEdited' => 'User successfully edited.',
|
||||
|
||||
];
|
||||
@@ -41,6 +41,22 @@
|
||||
{{ $errors->first('role') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<label>
|
||||
@lang('admin/userManagement.status')
|
||||
|
||||
<select name="status">
|
||||
@foreach($states as $status => $translation)
|
||||
<option value="{{$status}}" @if($status == $user->status) selected @endif>@lang($translation)</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@if (isset($errors) && $errors->has('role'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('role') }}
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
<label>
|
||||
|
||||
Reference in New Issue
Block a user