basic roles
This commit is contained in:
parent
0ffceb535d
commit
490bc64f41
4 changed files with 19 additions and 33 deletions
|
@ -26,6 +26,7 @@ use Illuminate\Support\HtmlString;
|
|||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
@ -108,9 +109,11 @@ class UserController extends Controller
|
|||
*/
|
||||
public function edit(User $user, GeneralSettings $general_settings)
|
||||
{
|
||||
$roles = Role::all();
|
||||
return view('admin.users.edit')->with([
|
||||
'user' => $user,
|
||||
'credits_display_name' => $general_settings->credits_display_name
|
||||
'credits_display_name' => $general_settings->credits_display_name,
|
||||
'roles' => $roles
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -135,6 +138,11 @@ class UserController extends Controller
|
|||
'referral_code' => "required|string|min:2|max:32|unique:users,referral_code,{$user->id}",
|
||||
]);
|
||||
|
||||
//update roles
|
||||
if ($request->roles) {
|
||||
$user->syncRoles($request->roles);
|
||||
}
|
||||
|
||||
if (isset($this->pterodactyl->getUser($request->input('pterodactyl_id'))['errors'])) {
|
||||
throw ValidationException::withMessages([
|
||||
'pterodactyl_id' => [__("User does not exists on pterodactyl's panel")],
|
||||
|
@ -329,22 +337,13 @@ class UserController extends Controller
|
|||
';
|
||||
})
|
||||
->editColumn('role', function (User $user) {
|
||||
switch ($user->role) {
|
||||
case 'admin':
|
||||
$badgeColor = 'badge-danger';
|
||||
break;
|
||||
case 'moderator':
|
||||
$badgeColor = 'badge-info';
|
||||
break;
|
||||
case 'client':
|
||||
$badgeColor = 'badge-success';
|
||||
break;
|
||||
default:
|
||||
$badgeColor = 'badge-secondary';
|
||||
break;
|
||||
$html = '';
|
||||
|
||||
foreach ($user->roles as $role) {
|
||||
$html .= "<span style='background-color: $role->color' class='badge'>$role->name</span>";
|
||||
}
|
||||
|
||||
return '<span class="badge ' . $badgeColor . '">' . $user->role . '</span>';
|
||||
return $html;
|
||||
})
|
||||
->editColumn('last_seen', function (User $user) {
|
||||
return $user->last_seen ? $user->last_seen->diffForHumans() : __('Never');
|
||||
|
|
|
@ -26,27 +26,12 @@ class ProfileController extends Controller
|
|||
/** Display a listing of the resource. */
|
||||
public function index(UserSettings $user_settings, DiscordSettings $discord_settings, ReferralSettings $referral_settings)
|
||||
{
|
||||
switch (Auth::user()->role) {
|
||||
case 'admin':
|
||||
$badgeColor = 'badge-danger';
|
||||
break;
|
||||
case 'mod':
|
||||
$badgeColor = 'badge-info';
|
||||
break;
|
||||
case 'client':
|
||||
$badgeColor = 'badge-success';
|
||||
break;
|
||||
default:
|
||||
$badgeColor = 'badge-secondary';
|
||||
break;
|
||||
}
|
||||
|
||||
return view('profile.index')->with([
|
||||
'user' => Auth::user(),
|
||||
'credits_reward_after_verify_discord' => $user_settings->credits_reward_after_verify_discord,
|
||||
'force_email_verification' => $user_settings->force_email_verification,
|
||||
'force_discord_verification' => $user_settings->force_discord_verification,
|
||||
'badgeColor' => $badgeColor,
|
||||
'discord_client_id' => $discord_settings->client_id,
|
||||
'discord_client_secret' => $discord_settings->client_secret,
|
||||
'referral_enabled' => $referral_settings->enabled,
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
@if(isset($user) && $user->roles->contains($role)) selected
|
||||
@endif value="{{$role->id}}">{{$role->name}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
|
|
@ -118,8 +118,10 @@
|
|||
@endif
|
||||
</div>
|
||||
|
||||
<div class="text-center text-sm-right"><span
|
||||
class="badge {{$badgeColor}}">{{ $user->role }}</span>
|
||||
<div class="text-center text-sm-right">
|
||||
@foreach ($user->roles as $role)
|
||||
<span style='background-color: {{$role->color}}' class='badge'>{{$role->name}}</span>
|
||||
@endforeach
|
||||
<div class="text-muted">
|
||||
<small>{{ $user->created_at->isoFormat('LL') }}</small>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue