working on UserCreate form...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from 'App/Models/User'
|
||||
import Database from '@ioc:Adonis/Lucid/Database'
|
||||
import { schema, rules } from '@ioc:Adonis/Core/Validator'
|
||||
|
||||
export default class UsersController {
|
||||
public async index({ inertia, bouncer }: HttpContextContract) {
|
||||
@@ -22,7 +23,40 @@ export default class UsersController {
|
||||
return inertia.render('Users/Create')
|
||||
}
|
||||
|
||||
public async store({}: HttpContextContract) {}
|
||||
public async store({ bouncer, inertia, request }: HttpContextContract) {
|
||||
await bouncer
|
||||
.with('UserPolicy')
|
||||
.authorize('store')
|
||||
|
||||
const newUserSchema = schema.create({
|
||||
username: schema.string(
|
||||
{ trim: true },
|
||||
[
|
||||
rules.unique({ table: 'users', column: 'username' })
|
||||
]
|
||||
),
|
||||
is_admin: schema.boolean(),
|
||||
password: schema.string([
|
||||
rules.confirmed("passwordRepeat")
|
||||
]),
|
||||
password_repeat: schema.string(),
|
||||
})
|
||||
console.log(request.body())
|
||||
|
||||
const payload = await request.validate({ schema: newUserSchema })
|
||||
console.log(payload)
|
||||
|
||||
if(request.qs().validate) {
|
||||
console.log("darf ich jetzt einen user erstellen?")
|
||||
await User.create({
|
||||
username: payload.username,
|
||||
isAdmin: payload.is_admin,
|
||||
password: payload.password,
|
||||
})
|
||||
|
||||
return inertia.render('Users')
|
||||
}
|
||||
}
|
||||
|
||||
public async show({ bouncer, params, inertia }: HttpContextContract) {
|
||||
const queriedUser: User = await User.findByOrFail('id', params.id)
|
||||
|
||||
Reference in New Issue
Block a user