working on AuthController
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from 'App/Models/User'
|
||||
|
||||
export default class UsersController {
|
||||
public async index({}: HttpContextContract) {}
|
||||
public async index({}: HttpContextContract) {
|
||||
|
||||
public async create({}: HttpContextContract) {}
|
||||
}
|
||||
|
||||
public async create({ auth, inertia }: HttpContextContract) {
|
||||
if(auth.user?.isAdmin) {
|
||||
inertia.render('Users/Create')
|
||||
} else {
|
||||
inertia
|
||||
}
|
||||
}
|
||||
|
||||
public async store({}: HttpContextContract) {}
|
||||
|
||||
@@ -13,5 +22,17 @@ export default class UsersController {
|
||||
|
||||
public async update({}: HttpContextContract) {}
|
||||
|
||||
public async destroy({}: HttpContextContract) {}
|
||||
public async destroy({ auth, response, params }: HttpContextContract) {
|
||||
if (auth.user?.isAdmin){
|
||||
const user = await User.findOrFail(params.id)
|
||||
await user.delete()
|
||||
.then(
|
||||
() => {
|
||||
response.redirect('users.index')
|
||||
},
|
||||
)
|
||||
// TODO implement reasonable error handling.
|
||||
.catch(error => console.log(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user