Skip to content

Commit

Permalink
Update players page, update routes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeke committed Jul 21, 2024
1 parent 750134b commit 759d916
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 102 deletions.
24 changes: 24 additions & 0 deletions app/Http/Middleware/Administrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class Administrator
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (!auth()->user()->is_admin) {
abort(403);
}

return $next($request);
}
}
11 changes: 1 addition & 10 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@

class UserPolicy
{
/**
* Determine whether the user can update the model.
*/
public function update(User $user, User $model): bool
{
//
return ($user->id === $model->created_by) || $user->isAdmin();
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, User $model): bool
{
return ($user->id === $model->created_by) || $user->isAdmin();
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, User $model): bool
{
return ($user->id === $model->created_by) || $user->isAdmin();
Expand Down
49 changes: 11 additions & 38 deletions resources/js/Pages/Players.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head, usePage, useForm, router } from '@inertiajs/vue3';
import { Head, usePage, useForm } from '@inertiajs/vue3';
import InputError from '@/Components/InputError.vue';
import { ref, computed, onMounted } from 'vue';
let isCreate = true;
let editModal = ref(null);
let deleteModal = ref(null);
let inviteUserModal = ref(null);
onMounted(() => {
editModal = new Modal('#editModal', {backdrop: 'static', keyboard: false});
deleteModal = new Modal('#deleteModal', {backdrop: 'static', keyboard: false});
inviteUserModal = new Modal('#inviteUserModal', {backdrop: 'static', keyboard: false});
});
const players = computed(() => usePage().props.players);
Expand All @@ -22,6 +20,7 @@
const form = useForm({
id: null,
name: '',
email: ''
});
const openEditModal = (player) => {
Expand All @@ -32,6 +31,7 @@
isCreate = false;
form.id = player.id;
form.name = player.name;
form.email = player.email;
}
editModal.show();
Expand All @@ -48,12 +48,6 @@
deleteModal.show();
}
const openInviteUserModalModal = (player) => {
form.reset();
inviteUserModal.show();
}
const save = () => {
const method = isCreate ? 'post' : 'patch';
const endpoint = isCreate ? 'player.store' : 'player.update';
Expand All @@ -70,10 +64,6 @@
}
});
};
const inviteAsUser = () => {
// TODO
}
</script>

<template>
Expand Down Expand Up @@ -102,7 +92,6 @@
<div class="actions" v-if="user.id !== player.id">
<button class="btn btn-sm btn-outline-gray-500" @click="openEditModal(player)"><i class="bi bi-pencil"></i> Edit</button>
<button v-if="user.is_admin" class="btn btn-sm btn-outline-danger" @click="openDeleteModal(player)"><i class="bi bi-trash-fill"></i> Delete</button>
<button class="btn btn-invite-user" @click="openInviteUserModalModal(player)"><i class="bi bi-person-plus"></i></button>
</div>
</div>
</div>
Expand All @@ -119,12 +108,18 @@
</div>
<div class="modal-body">
<div class="form-floating mb-3">
<input class="form-control" id="name" v-model="form.name" placeholder="Player name" @keyup.enter="save" />
<label class="form-label sr-only" for="name">Player name</label>
<input class="form-control" id="name" v-model="form.name" placeholder="Name" @keyup.enter="save" />
<label class="form-label sr-only" for="name">Name *</label>

<InputError :message="form.errors.name" class="mt-2" />
</div>

<div class="form-floating mb-3">
<input class="form-control" id="email" v-model="form.email" placeholder="Emailaddress">
<label class="form-label" for="email">Emailaddress</label>
<div class="form-text fst-italic">Entering an emailaddress will send an invite to create a user account.</div>
</div>

<div class="mt-4 d-flex">
<button class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
<button class="btn btn-primary ms-auto" :disabled="form.processing" @click="save">Save</button>
Expand Down Expand Up @@ -154,27 +149,5 @@
</div>
</div>

<div class="modal" id="inviteUserModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Invite player as user</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Here you can invite this player for a user account.</p>
<p><b>{{ form.name }}</b></p>

<p>TODO: add form with email address.</p>

<div class="mt-4 d-flex">
<button class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
<button class="btn btn-primary ms-auto" @click="inviteAsUser">Send invite</button>
</div>
</div>
</div>
</div>
</div>

</AuthenticatedLayout>
</template>
42 changes: 0 additions & 42 deletions routes/auth.php

This file was deleted.

52 changes: 40 additions & 12 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\GameController;
use App\Http\Controllers\GameScoreController;
use App\Http\Controllers\PlayerController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\ConfirmablePasswordController;
use App\Http\Controllers\Auth\EmailVerificationNotificationController;
use App\Http\Controllers\Auth\EmailVerificationPromptController;
use App\Http\Controllers\Auth\NewPasswordController;
use App\Http\Controllers\Auth\PasswordController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\VerifyEmailController;
use App\Http\Middleware\Administrator;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/dashboard', function () {
return redirect('/');
});
Expand Down Expand Up @@ -45,4 +45,32 @@
Route::delete('/player', [PlayerController::class, 'delete'])->name('player.delete');
});

require __DIR__.'/auth.php';
Route::middleware('guest')->group(function () {
// Disabled registration for now
Route::get('register', [RegisteredUserController::class, 'create'])->name('register');
Route::post('register', [RegisteredUserController::class, 'store']);

Route::get('login', [AuthenticatedSessionController::class, 'create'])->name('login');
Route::post('login', [AuthenticatedSessionController::class, 'store']);

Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])->name('password.request');
Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])->name('password.email');
Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])->name('password.reset');
Route::post('reset-password', [NewPasswordController::class, 'store'])->name('password.store');
});

Route::middleware('auth')->group(function () {
Route::get('verify-email', EmailVerificationPromptController::class)->name('verification.notice');
Route::get('verify-email/{id}/{hash}', VerifyEmailController::class)->middleware(['signed', 'throttle:6,1'])->name('verification.verify');
Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store'])->middleware('throttle:6,1')->name('verification.send');
Route::get('confirm-password', [ConfirmablePasswordController::class, 'show'])->name('password.confirm');
Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']);
Route::put('password', [PasswordController::class, 'update'])->name('password.update');
Route::post('logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout');
});

Route::group(['middleware' => ['auth', Administrator::class]], function() {
Route::get('/admin', function() {
return view('admin');
});
});

0 comments on commit 759d916

Please sign in to comment.