feat(*) initial commit

This commit is contained in:
Harminder Virk
2017-08-20 22:39:25 +05:30
commit 991657c76b
28 changed files with 1094 additions and 0 deletions

20
app/Models/Hooks/User.js Normal file
View 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
View 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
View 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