|
|
@@ -1,5 +1,5 @@
|
|
|
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
|
-import User from 'App/Models/User'
|
|
|
+import User, { UserRoles } from 'App/Models/User'
|
|
|
import PaginationService from 'App/Services/PaginationService'
|
|
|
import { schema, rules } from '@ioc:Adonis/Core/Validator'
|
|
|
import randomstring from 'randomstring'
|
|
|
@@ -20,6 +20,21 @@ export default class UsersController {
|
|
|
return await User.create(request.all())
|
|
|
}
|
|
|
|
|
|
+ public async newAdminUser({ request, bouncer }: HttpContextContract) {
|
|
|
+ await bouncer.authorize('admin')
|
|
|
+ const data = await request.validate({
|
|
|
+ schema: schema.create({
|
|
|
+ username: schema.string([]),
|
|
|
+ password: schema.string([]),
|
|
|
+ email: schema.string.optional([rules.email()])
|
|
|
+ })
|
|
|
+ })
|
|
|
+ return await User.create({
|
|
|
+ ...data,
|
|
|
+ role: UserRoles.Admin
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
public async show({ params }: HttpContextContract) {
|
|
|
return await User.findOrFail(params.id)
|
|
|
}
|