Added database, orm, auth modules
added db migrations for users and initial data added first controllers added auth middleware added rest routes and controller stub ...
This commit is contained in:
33
app/Models/User.ts
Normal file
33
app/Models/User.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { DateTime } from 'luxon'
|
||||
import Hash from '@ioc:Adonis/Core/Hash'
|
||||
import { column, beforeSave, BaseModel } from '@ioc:Adonis/Lucid/Orm'
|
||||
|
||||
export default class User extends BaseModel {
|
||||
@column({ isPrimary: true })
|
||||
public id: number
|
||||
|
||||
@column()
|
||||
public username: string
|
||||
|
||||
@column({ serializeAs: null })
|
||||
public password: string
|
||||
|
||||
@column()
|
||||
public isAdmin: boolean
|
||||
|
||||
@column()
|
||||
public rememberMeToken: string | null
|
||||
|
||||
@column.dateTime({ autoCreate: true })
|
||||
public createdAt: DateTime
|
||||
|
||||
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||
public updatedAt: DateTime
|
||||
|
||||
@beforeSave()
|
||||
public static async hashPassword (user: User) {
|
||||
if (user.$dirty.password) {
|
||||
user.password = await Hash.make(user.password)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user