added login / logout functionality and authorization rules via bouncer

This commit is contained in:
Sockenklaus
2021-10-17 17:11:21 +02:00
parent 43ee300bd2
commit 4b222c9921
14 changed files with 665 additions and 18 deletions

View File

@@ -0,0 +1,23 @@
import Hash from '@ioc:Adonis/Core/Hash'
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
import User from 'App/Models/User'
export default class Users extends BaseSchema {
protected tableName = 'users'
public async up () {
this.schema.alterTable(this.tableName, (table) => {
table.boolean('is_active').defaultTo(false)
table.string('role')
.defaultTo('employee')
.notNullable()
})
}
public async down () {
this.schema.alterTable(this.tableName, (table) => {
table.dropColumn('is_active')
table.dropColumn('role')
})
}
}

View File

@@ -0,0 +1,31 @@
import BaseSeeder from '@ioc:Adonis/Lucid/Seeder'
import Logger from '@ioc:Adonis/Core/Logger'
import Employee from 'App/Models/Employee'
export default class EmployeeSeeder extends BaseSeeder {
public async run () {
try {
await Employee.createMany([
{
firstName: 'Pascal',
lastName: 'König',
shorthand: 'PK'
},
{
firstName: 'Sandra',
lastName: 'Sühl',
shorthand: 'SS'
},
{
firstName: 'Karin',
lastName: 'Behr',
shorthand: 'KB'
}
])
} catch (error) {
Logger.error(error)
}
}
}

21
database/seeders/User.ts Normal file
View File

@@ -0,0 +1,21 @@
import BaseSeeder from '@ioc:Adonis/Lucid/Seeder'
import User from 'App/Models/User'
import Logger from '@ioc:Adonis/Core/Logger'
export default class UserSeeder extends BaseSeeder {
public async run () {
try {
await User.create({
username: 'admin',
password: 'admin',
role: 'admin',
email: 'test@test.de',
isActive: true
})
}
catch(error) {
Logger.error(error.message)
}
}
}