diff --git a/app/Controllers/Http/AuthController.ts b/app/Controllers/Http/AuthController.ts
index fc7574d..1416c8d 100644
--- a/app/Controllers/Http/AuthController.ts
+++ b/app/Controllers/Http/AuthController.ts
@@ -3,10 +3,12 @@ import { schema } from '@ioc:Adonis/Core/Validator'
import Logger from '@ioc:Adonis/Core/Logger'
export default class AuthController {
- public async login({ auth, request, session, response }: HttpContextContract){
+ public async login({ auth, request, response }: HttpContextContract){
- const { username, password } = request.all()
- /*const loginSchema = schema.create({
+ Logger.info("entering login")
+ Logger.info(JSON.stringify(request.all()))
+
+ const loginSchema = schema.create({
username: schema.string({trim: true}),
password: schema.string()
})
@@ -14,18 +16,12 @@ export default class AuthController {
const { username, password } = await request.validate({
schema: loginSchema,
messages: {
- required: 'This field is required'
+ required: 'This field is required'
}
- })*/
+ })
- try {
- await auth.attempt(username, password)
-
- response.redirect('/events')
- } catch (error) {
- session.flash("notification", "Login fehlgeschlagen")
- response.redirect("/")
- }
+ await auth.attempt(username, password)
+ response.redirect().toRoute('events.index')
}
public async logout({ auth, response }: HttpContextContract) {
diff --git a/app/Controllers/Http/UsersController.ts b/app/Controllers/Http/UsersController.ts
index dd8dc32..8d488d3 100644
--- a/app/Controllers/Http/UsersController.ts
+++ b/app/Controllers/Http/UsersController.ts
@@ -1,16 +1,21 @@
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import User from 'App/Models/User'
+import Logger from '@ioc:Adonis/Core/Logger'
export default class UsersController {
- public async index({}: HttpContextContract) {
+ public async index({ auth, response, inertia }: HttpContextContract) {
+ if(auth.user?.isAdmin) {
+ return inertia.render('Users/Index')
+ }
+ else response.redirect().toRoute('events.index')
}
public async create({ auth, inertia }: HttpContextContract) {
if(auth.user?.isAdmin) {
inertia.render('Users/Create')
} else {
- inertia
+
}
}
diff --git a/app/Exceptions/Handler.ts b/app/Exceptions/Handler.ts
index beb1ae1..f47c5ec 100644
--- a/app/Exceptions/Handler.ts
+++ b/app/Exceptions/Handler.ts
@@ -15,6 +15,7 @@
import Logger from '@ioc:Adonis/Core/Logger'
import HttpExceptionHandler from '@ioc:Adonis/Core/HttpExceptionHandler'
+import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class ExceptionHandler extends HttpExceptionHandler {
protected statusPages = {
@@ -26,4 +27,21 @@ export default class ExceptionHandler extends HttpExceptionHandler {
constructor() {
super(Logger)
}
+
+ public async handle(error: any, ctx: HttpContextContract) {
+ const { session, response } = ctx;
+
+ /**
+ * Handle failed authentication attempt
+ */
+ if (['E_INVALID_AUTH_PASSWORD', 'E_INVALID_AUTH_UID'].includes(error.code)) {
+ session.flash('errors', { login: error.message });
+ return response.redirect().back();
+ }
+
+ /**
+ * Forward rest of the exceptions to the parent class
+ */
+ return super.handle(error, ctx);
+ }
}
diff --git a/components.d.ts b/components.d.ts
index b165ab7..e28c154 100644
--- a/components.d.ts
+++ b/components.d.ts
@@ -7,10 +7,12 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
+ NAlert: typeof import('naive-ui')['NAlert']
NButton: typeof import('naive-ui')['NButton']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NInput: typeof import('naive-ui')['NInput']
NMenu: typeof import('naive-ui')['NMenu']
+ NMessageProvider: typeof import('naive-ui')['NMessageProvider']
}
}
diff --git a/resources/js/Layouts/BELayout.vue b/resources/js/Layouts/BELayout.vue
index 9306048..108a9ea 100644
--- a/resources/js/Layouts/BELayout.vue
+++ b/resources/js/Layouts/BELayout.vue
@@ -1,7 +1,7 @@
-
+
diff --git a/resources/js/Layouts/LoginLayout.vue b/resources/js/Layouts/LoginLayout.vue
index 0bec86b..7720716 100644
--- a/resources/js/Layouts/LoginLayout.vue
+++ b/resources/js/Layouts/LoginLayout.vue
@@ -1,7 +1,9 @@
-
+
+
+
\ No newline at end of file
diff --git a/resources/js/components/MainNav.vue b/resources/js/components/MainNav.vue
index ccd8972..a6550db 100644
--- a/resources/js/components/MainNav.vue
+++ b/resources/js/components/MainNav.vue
@@ -4,7 +4,7 @@
\ No newline at end of file
diff --git a/resources/js/pages/Users/Index.vue b/resources/js/pages/Users/Index.vue
index d65dca5..a9b9ead 100644
--- a/resources/js/pages/Users/Index.vue
+++ b/resources/js/pages/Users/Index.vue
@@ -1,5 +1,7 @@
-
+
+ Bin in Users
+