58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Privilege;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class UsersController extends BaseController
|
|
{
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
|
|
|
public function overview() {
|
|
$user = Auth::user();
|
|
if(!$user->hasPrivilege("admin")) {
|
|
return response('Unauthenticated.', 401);
|
|
}
|
|
|
|
$users = User::query()->get();
|
|
|
|
return view("users.overview", ["users" => $users]);
|
|
}
|
|
|
|
public function updateUser(Request $request) {
|
|
$user = Auth::user();
|
|
if(!$user->hasPrivilege("admin")) {
|
|
return response('Unauthenticated.', 401);
|
|
}
|
|
|
|
$validatedData = $request->validate([
|
|
'id' => ['required', 'integer'],
|
|
'createVPN' => ['boolean'],
|
|
'admin' => ['boolean']
|
|
]);
|
|
|
|
$p = Privilege::query()->where("user_id", "=", $validatedData["id"])->first();
|
|
|
|
if(isset($validatedData["createVPN"]) && $validatedData["createVPN"]) {
|
|
$p->createVPN = true;
|
|
} else {
|
|
$p->createVPN = false;
|
|
}
|
|
|
|
if(isset($validatedData["admin"]) && $validatedData["admin"]) {
|
|
$p->admin = true;
|
|
} else {
|
|
$p->admin = false;
|
|
}
|
|
|
|
$p->saveOrFail();
|
|
return redirect("/users");
|
|
}
|
|
}
|