working on flashmessages
This commit is contained in:
@@ -1,18 +1,16 @@
|
|||||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
import { schema } from '@ioc:Adonis/Core/Validator'
|
import { schema } from '@ioc:Adonis/Core/Validator'
|
||||||
import Logger from '@ioc:Adonis/Core/Logger'
|
|
||||||
|
|
||||||
export default class AuthController {
|
export default class AuthController {
|
||||||
public async login({ auth, request, response }: HttpContextContract){
|
public async login({ auth, request, response, session }: HttpContextContract){
|
||||||
|
|
||||||
Logger.info("entering login")
|
|
||||||
Logger.info(JSON.stringify(request.all()))
|
|
||||||
|
|
||||||
const loginSchema = schema.create({
|
const loginSchema = schema.create({
|
||||||
username: schema.string({trim: true}),
|
username: schema.string({trim: true}),
|
||||||
password: schema.string()
|
password: schema.string()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const { username, password } = await request.validate({
|
const { username, password } = await request.validate({
|
||||||
schema: loginSchema,
|
schema: loginSchema,
|
||||||
messages: {
|
messages: {
|
||||||
@@ -24,9 +22,14 @@ export default class AuthController {
|
|||||||
response.redirect().toRoute('events.index')
|
response.redirect().toRoute('events.index')
|
||||||
}
|
}
|
||||||
|
|
||||||
public async logout({ auth, response }: HttpContextContract) {
|
public async logout({ auth, response, session }: HttpContextContract) {
|
||||||
await auth.logout()
|
await auth.logout()
|
||||||
|
|
||||||
|
session.flash('errors', {
|
||||||
|
logout: 'test'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
response.redirect('/login')
|
response.redirect('/login')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
components.d.ts
vendored
1
components.d.ts
vendored
@@ -7,7 +7,6 @@ export {}
|
|||||||
|
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
NAlert: typeof import('naive-ui')['NAlert']
|
|
||||||
NButton: typeof import('naive-ui')['NButton']
|
NButton: typeof import('naive-ui')['NButton']
|
||||||
NForm: typeof import('naive-ui')['NForm']
|
NForm: typeof import('naive-ui')['NForm']
|
||||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<main class="bg-slate-100 flex justify-center h-screen">
|
<main class="bg-slate-100 flex justify-center h-screen">
|
||||||
<div class="m-auto bg-white p-4 border rounded space-y-4 drop-shadow">
|
<div class="m-auto bg-white p-4 border rounded space-y-4 drop-shadow">
|
||||||
<n-message-provider>
|
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</n-message-provider>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-menu v-model:value="activeKey" mode="horizontal" :options="menuOptions" />
|
<n-menu
|
||||||
|
v-model:value="activeKey"
|
||||||
|
mode="horizontal"
|
||||||
|
:options="menuOptions"
|
||||||
|
class="-mx-4"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -12,47 +17,51 @@
|
|||||||
LogOutFilled as Logout
|
LogOutFilled as Logout
|
||||||
} from '@vicons/material'
|
} from '@vicons/material'
|
||||||
|
|
||||||
const { request } = usePage().props
|
const { request, isAdmin } = usePage().props
|
||||||
const activeKey = ref(request.url)
|
const activeKey = ref(request.url)
|
||||||
|
|
||||||
const menuOptions = ref([
|
const menuOptions = ref([])
|
||||||
{
|
menuOptions.value.push({
|
||||||
label: () =>
|
label: () =>
|
||||||
h(
|
h(
|
||||||
Link, {
|
Link, {
|
||||||
href: "/events",
|
href: "/events",
|
||||||
methode: "get"
|
methode: "get"
|
||||||
},
|
},
|
||||||
"Veranstaltungen"
|
() => "Veranstaltungen"
|
||||||
),
|
),
|
||||||
key: '/events',
|
key: '/events',
|
||||||
icon: renderIcon(Events)
|
icon: renderIcon(Events)
|
||||||
},
|
})
|
||||||
{
|
|
||||||
label: () =>
|
if(isAdmin) menuOptions.value.push({
|
||||||
h(
|
label: () =>
|
||||||
Link, {
|
h(
|
||||||
href: "/users",
|
Link, {
|
||||||
method: "get"
|
href: "/users",
|
||||||
},
|
method: "get"
|
||||||
"Benutzer"
|
},
|
||||||
),
|
() => "Benutzer"
|
||||||
key: '/users',
|
),
|
||||||
icon: renderIcon(Users)
|
key: '/users',
|
||||||
},
|
icon: renderIcon(Users)
|
||||||
{
|
})
|
||||||
label: () =>
|
|
||||||
h(
|
menuOptions.value.push({
|
||||||
Link, {
|
label: () =>
|
||||||
href: "/login",
|
h(
|
||||||
method: "get"
|
Link, {
|
||||||
},
|
href: "/logout",
|
||||||
"Abmelden"
|
method: "post",
|
||||||
),
|
as: "button"
|
||||||
key: '/logout',
|
},
|
||||||
icon: renderIcon(Logout)
|
() => "Abmelden"
|
||||||
}
|
),
|
||||||
])
|
key: '/logout',
|
||||||
|
icon: renderIcon(Logout)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function renderIcon(icon) {
|
function renderIcon(icon) {
|
||||||
return () => h(NIcon, null, { default: () => h(icon) })
|
return () => h(NIcon, null, { default: () => h(icon) })
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<n-message-provider>
|
||||||
|
<FlashMessages
|
||||||
|
:messages="props.flashMessages"
|
||||||
|
/>
|
||||||
|
</n-message-provider>
|
||||||
<n-form
|
<n-form
|
||||||
label-placement="top"
|
label-placement="top"
|
||||||
:model="form"
|
:model="form"
|
||||||
@@ -44,14 +48,12 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, watch } from 'vue'
|
import { ref, reactive, watch } from 'vue'
|
||||||
import { useMessage } from 'naive-ui'
|
|
||||||
import { router } from '@inertiajs/vue3'
|
import { router } from '@inertiajs/vue3'
|
||||||
import LoginLayout from '@/layouts/LoginLayout.vue'
|
import LoginLayout from '@/layouts/LoginLayout.vue'
|
||||||
|
import FlashMessages from '@/components/FlashMessages'
|
||||||
|
|
||||||
defineOptions({ layout: LoginLayout })
|
defineOptions({ layout: LoginLayout })
|
||||||
const message = useMessage()
|
const props = defineProps(['flashMessages'])
|
||||||
const props = defineProps(['errors'])
|
|
||||||
const flashErrors = ref(props.errors)
|
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
username: '',
|
username: '',
|
||||||
@@ -73,16 +75,6 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(props, async(newVal, oldVal) => {
|
|
||||||
flashErrors.value = props.errors
|
|
||||||
|
|
||||||
if(flashErrors.value?.login) {
|
|
||||||
message.error(translateLoginError(flashErrors.value.login),{
|
|
||||||
closable: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function translateLoginError(errorMsg) {
|
function translateLoginError(errorMsg) {
|
||||||
switch(errorMsg.split(":")[0]) {
|
switch(errorMsg.split(":")[0]) {
|
||||||
case 'E_INVALID_AUTH_PASSWORD':
|
case 'E_INVALID_AUTH_PASSWORD':
|
||||||
@@ -93,7 +85,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onClickLogin(){
|
function onClickLogin(){
|
||||||
flashErrors.value = null
|
|
||||||
formRef.value?.validate((errors) => {
|
formRef.value?.validate((errors) => {
|
||||||
if(!errors) router.post('login', form.value)
|
if(!errors) router.post('login', form.value)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,9 +11,8 @@
|
|||||||
import Inertia from '@ioc:EidelLev/Inertia'
|
import Inertia from '@ioc:EidelLev/Inertia'
|
||||||
|
|
||||||
Inertia.share({
|
Inertia.share({
|
||||||
errors: ({session}) => {
|
//errors: ({session}) => session.flashMessages.get('errors'),
|
||||||
return session.flashMessages.get('errors')
|
|
||||||
},
|
|
||||||
request: ({ request }) => request,
|
request: ({ request }) => request,
|
||||||
isAdmin: ({ auth }) => auth.user?.isAdmin,
|
isAdmin: ({ auth }) => auth.user?.isAdmin,
|
||||||
|
flashMessages: ({ session }) => session.flashMessages.all(),
|
||||||
}).version(() => Inertia.manifestFile('public/assets/manifest.json'))
|
}).version(() => Inertia.manifestFile('public/assets/manifest.json'))
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Route.get('/', 'HomeController.index')
|
|||||||
Route.get('/login', async({inertia}: HttpContextContract) =>{
|
Route.get('/login', async({inertia}: HttpContextContract) =>{
|
||||||
return inertia.render('Login')
|
return inertia.render('Login')
|
||||||
})
|
})
|
||||||
|
Route.post('/logout', 'AuthController.logout')
|
||||||
|
|
||||||
Route.post('login', 'AuthController.login')
|
Route.post('login', 'AuthController.login')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user