Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 50-crud-for-schools-frontend
  • Loading branch information
AmonDeShir committed Dec 2, 2024
2 parents 6431cf2 + 5bb76a9 commit 3322e8a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 55 deletions.
4 changes: 1 addition & 3 deletions app/Http/Controllers/AuthenticateSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
22 changes: 0 additions & 22 deletions resources/js/Layouts/AdminLayout.vue

This file was deleted.

22 changes: 21 additions & 1 deletion resources/js/Layouts/BaseLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<PageProps>()
const status = ref<string | undefined>(props.flash.status)
watch(() => props.flash, flash => {
Expand All @@ -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'})
}
</script>

<template>
Expand Down
17 changes: 0 additions & 17 deletions resources/js/Layouts/UserLayout.vue

This file was deleted.

11 changes: 3 additions & 8 deletions resources/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import '../css/app.css'
import { createApp, h, type DefineComponent } from 'vue'
import { createInertiaApp } from '@inertiajs/vue3'
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'
import UserLayout from '@/Layouts/UserLayout.vue'
import AdminLayout from '@/Layouts/AdminLayout.vue'
import BaseLayout from '@/Layouts/BaseLayout.vue'
import GuestLayout from '@/Layouts/GuestLayout.vue'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
Expand All @@ -22,12 +21,8 @@ createInertiaApp({
import.meta.glob<DefineComponent>('./Pages/**/*.vue'),
)

if (name.startsWith('Admin/')) {
page.default.layout ??= AdminLayout
}

if (name.startsWith('User/')) {
page.default.layout ??= UserLayout
if (name.startsWith('Admin/') || name.startsWith('User/')) {
page.default.layout ??= BaseLayout
}

if (name.startsWith('Guest/')) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/AuthenticateSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testUserCanLogin(): void
"email" => "[email protected]",
"password" => "goodPassword",
])
->assertRedirect("/dashboard");
->assertRedirect("/");
}

public function testUserCanNotLoginWithWrongPassword(): void
Expand Down Expand Up @@ -66,7 +66,7 @@ public function testUnverifiedUserCanLogin(): void
"email" => "[email protected]",
"password" => "goodPassword",
])
->assertRedirect("/dashboard");
->assertRedirect("/");
}

public function testUnverifiedUserIsRedirectedToVerifyEmail(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testUserCanResetPasswordWithValidToken(): void
"password" => "newPassword",
]);

$loginResponse->assertRedirect("/dashboard");
$loginResponse->assertRedirect("/");
$this->assertAuthenticated();
Event::assertDispatched(PasswordReset::class);
}
Expand Down

0 comments on commit 3322e8a

Please sign in to comment.