diff --git a/app/Http/Controllers/AuthenticateSessionController.php b/app/Http/Controllers/AuthenticateSessionController.php index 58fb4374..61cc4a9e 100644 --- a/app/Http/Controllers/AuthenticateSessionController.php +++ b/app/Http/Controllers/AuthenticateSessionController.php @@ -21,9 +21,7 @@ public function authenticate(AuthenticateSessionRequest $request): RedirectRespo if (auth()->attempt($credentials)) { $request->session()->regenerate(); - return $request->user()->hasRole(["admin", "super_admin"]) - ? Redirect::route("admin.quizzes.index") - : Redirect::route("dashboard"); + return redirect()->route("home"); } throw ValidationException::withMessages([ diff --git a/app/Http/Controllers/ContestController.php b/app/Http/Controllers/ContestController.php index e5ffac73..5d595d44 100644 --- a/app/Http/Controllers/ContestController.php +++ b/app/Http/Controllers/ContestController.php @@ -9,6 +9,7 @@ use App\Http\Resources\UserQuizResource; use App\Models\Quiz; use App\Models\School; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Inertia\Inertia; use Inertia\Response; @@ -22,9 +23,14 @@ public function index(): Response return Inertia::render("Home", ["schools" => SchoolResource::collection($schools)]); } - public function create(Request $request): Response + public function create(Request $request): RedirectResponse|Response { $user = $request->user(); + + if ($user->hasRole(["admin", "super_admin"])) { + return redirect()->route("admin.quizzes.index"); + } + $userQuizzes = $user->userQuizzes() ->with(["userQuestions.question.answers", "quiz"]) ->get(); diff --git a/resources/js/Layouts/AdminLayout.vue b/resources/js/Layouts/AdminLayout.vue deleted file mode 100644 index 5c121114..00000000 --- a/resources/js/Layouts/AdminLayout.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - diff --git a/resources/js/Layouts/BaseLayout.vue b/resources/js/Layouts/BaseLayout.vue index 13d691b2..3460e3e8 100644 --- a/resources/js/Layouts/BaseLayout.vue +++ b/resources/js/Layouts/BaseLayout.vue @@ -6,7 +6,7 @@ import Banner from '@/components/Common/Banner.vue' import {ref, watch} from 'vue' import {type PageProps} from '@/Types/PageProps' -const props = defineProps<{ pages: Page[] } & PageProps>() +const props = defineProps() const status = ref(props.flash.status) watch(() => props.flash, flash => { @@ -17,6 +17,26 @@ function hideMessage() { status.value = undefined } +const pages: Page[] = [] + +if (!!props.user?.isAdmin || props.user?.isSuperAdmin) { + pages.push( + { title: 'Testy', href: '/admin/quizzes' }, + { title: 'Szkoły', href: '/admin/schools' }, + { title: 'Uczniowie', href: '/admin/users' }, + ) +} +else { + pages.push({ title: 'Konkursy', href: '/dashboard' }) +} + +pages.push( + { title: 'Profil', href: '/profile' }, +) + +if (props.user?.isSuperAdmin) { + pages.push({ title: 'Administratorzy', href: '/admin/admins'}) +}