-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
67 lines (57 loc) · 1.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
//dependencies
const path = require('path');
const _ = require('lodash');
const libPath = path.join(__dirname, 'lib');
const morphsPath = path.join(libPath, 'morphs');
//load types
require(path.join(libPath, 'types', 'email'));
//require morphs
const Authenticable = require(path.join(morphsPath, 'authenticable'));
const Confirmable = require(path.join(morphsPath, 'confirmable'));
const Lockable = require(path.join(morphsPath, 'lockable'));
const Recoverable = require(path.join(morphsPath, 'recoverable'));
const Registerable = require(path.join(morphsPath, 'registerable'));
const Trackable = require(path.join(morphsPath, 'trackable'));
/**
* @function
* @description mongoose irina plugin
* @param {Schema} schema valid mongoose schema
* @param {Object} options valid mongoose irina plugin options
* @public
*/
module.exports = exports = function Irina(schema, optns) {
//prepare common options
const options = _.extend({
authenticationField: 'email',
confirmable: {
tokenLifeSpan: 3
},
lockable: {
tokenLifeSpan: 3,
maximumAllowedFailedAttempts: 3
},
recoverable: {
tokenLifeSpan: 3
},
registerable: {
autoConfirm: false
},
trackable: {}
}, optns || {});
//morph schema to be authenticable
//
//warn!:this is must morph for others
//morphs to work
Authenticable.call(null, schema, options);
//morph schema to be confirmable
Confirmable.call(null, schema, options);
//morph schema to be lockable
Lockable.call(null, schema, options);
//morph schema to be recoverable
Recoverable.call(null, schema, options);
//morph schema to be registerable
Registerable.call(null, schema, options);
//morph schema to be trackable
Trackable.call(null, schema, options);
};