- added working typescript support to vue
- added bouncer support - added UserPolicies - added first user index call
This commit is contained in:
@@ -2,7 +2,7 @@ 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){
|
||||
public async login({ auth, request, response }: HttpContextContract){
|
||||
|
||||
|
||||
const loginSchema = schema.create({
|
||||
@@ -18,27 +18,13 @@ export default class AuthController {
|
||||
}
|
||||
})
|
||||
|
||||
session.flash({
|
||||
login: {
|
||||
warning: 'test'
|
||||
}
|
||||
})
|
||||
|
||||
await auth.attempt(username, password)
|
||||
response.redirect().toRoute('events.index')
|
||||
}
|
||||
|
||||
public async logout({ auth, response, session }: HttpContextContract) {
|
||||
public async logout({ auth, response }: HttpContextContract) {
|
||||
await auth.logout()
|
||||
|
||||
session.flash('gfd', {
|
||||
warning: 'test'
|
||||
})
|
||||
session.flash('login', {
|
||||
warning: "noch eine warning"
|
||||
})
|
||||
|
||||
|
||||
response.redirect('/login')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from 'App/Models/User'
|
||||
import Logger from '@ioc:Adonis/Core/Logger'
|
||||
import Database from '@ioc:Adonis/Lucid/Database'
|
||||
|
||||
export default class UsersController {
|
||||
public async index({ auth, response, inertia }: HttpContextContract) {
|
||||
public async index({ inertia, bouncer }: HttpContextContract) {
|
||||
|
||||
if(auth.user?.isAdmin) {
|
||||
return inertia.render('Users/Index')
|
||||
}
|
||||
else response.redirect().toRoute('events.index')
|
||||
await bouncer.with('UserPolicy').authorize('index')
|
||||
|
||||
const users = await Database
|
||||
.from('users')
|
||||
.select('id', 'username', 'is_admin')
|
||||
|
||||
return inertia.render('Users/Index', { users })
|
||||
}
|
||||
|
||||
public async create({ auth, inertia }: HttpContextContract) {
|
||||
|
||||
Reference in New Issue
Block a user