feat(*) initial commit
This commit is contained in:
20
app/Models/Hooks/User.js
Normal file
20
app/Models/Hooks/User.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const Hash = use('Hash')
|
||||
|
||||
const UserHook = module.exports = {}
|
||||
|
||||
/**
|
||||
* Hash using password as a hook.
|
||||
*
|
||||
* @method
|
||||
*
|
||||
* @param {Object} userInstance
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
UserHook.hashPassword = async (userInstance) => {
|
||||
if (userInstance.password) {
|
||||
userInstance.password = await Hash.make(userInstance.password)
|
||||
}
|
||||
}
|
||||
8
app/Models/Token.js
Normal file
8
app/Models/Token.js
Normal file
@@ -0,0 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const Model = use('Model')
|
||||
|
||||
class Token extends Model {
|
||||
}
|
||||
|
||||
module.exports = Token
|
||||
34
app/Models/User.js
Normal file
34
app/Models/User.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict'
|
||||
|
||||
const Model = use('Model')
|
||||
|
||||
class User extends Model {
|
||||
static boot () {
|
||||
super.boot()
|
||||
|
||||
/**
|
||||
* A hook to bash the user password before saving
|
||||
* it to the database.
|
||||
*
|
||||
* Look at `app/Models/Hooks/User.js` file to
|
||||
* check the hashPassword method
|
||||
*/
|
||||
this.addHook('beforeCreate', 'User.hashPassword')
|
||||
}
|
||||
|
||||
/**
|
||||
* A relationship on tokens is required for auth to
|
||||
* work. Since features like `refreshTokens` or
|
||||
* `rememberToken` will be saved inside the
|
||||
* tokens table.
|
||||
*
|
||||
* @method tokens
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
tokens () {
|
||||
return this.hasMany('App/Models/Token')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = User
|
||||
Reference in New Issue
Block a user