Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teacher auth #4

Merged
merged 10 commits into from
Jun 20, 2022
Prev Previous commit
Next Next commit
✨ feat: configuring teacher registration password encryption
  • Loading branch information
eukvyn committed Jun 20, 2022
commit 458cb9c5d50d7a5162733f161c70de64eb6f8100
11 changes: 10 additions & 1 deletion app/Models/Teacher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DateTime } from 'luxon'
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'
import { BaseModel, beforeSave, column } from '@ioc:Adonis/Lucid/Orm'

import Hash from '@ioc:Adonis/Core/Hash'

export default class Teacher extends BaseModel {
@column({ isPrimary: true })
Expand All @@ -19,4 +21,11 @@ export default class Teacher extends BaseModel {

@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime

@beforeSave()
public static async hashPassword(user: Teacher) {
if (user.$dirty.password) {
user.password = await Hash.make(user.password)
}
}
}