This repository has been archived on 2024-11-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
enzos-events/app/Controllers/Http/AuthController.ts
2023-07-07 23:33:59 +02:00

45 lines
1.1 KiB
TypeScript

import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import { schema } from '@ioc:Adonis/Core/Validator'
export default class AuthController {
public async login({ auth, request, response, session }: HttpContextContract){
const loginSchema = schema.create({
username: schema.string({trim: true}),
password: schema.string()
})
const { username, password } = await request.validate({
schema: loginSchema,
messages: {
required: 'This field is required'
}
})
session.flash({
login: {
warning: 'test'
}
})
await auth.attempt(username, password)
response.redirect().toRoute('events.index')
}
public async logout({ auth, response, session }: HttpContextContract) {
await auth.logout()
session.flash('gfd', {
warning: 'test'
})
session.flash('login', {
warning: "noch eine warning"
})
response.redirect('/login')
}
}