19 lines
545 B
JavaScript
19 lines
545 B
JavaScript
|
const models = require('vn-loopback/server/server').models;
|
||
|
|
||
|
module.exports = authCode = async(vnUser, options) => {
|
||
|
const myOptions = {};
|
||
|
|
||
|
if (typeof options == 'object')
|
||
|
Object.assign(myOptions, options);
|
||
|
|
||
|
const code = String(Math.floor(Math.random() * 999999));
|
||
|
console.log(code);
|
||
|
const maxTTL = ((60 * 1000) * 5); // 5 min
|
||
|
await models.AuthCode.upsertWithWhere({userFk: vnUser.id}, {
|
||
|
userFk: vnUser.id,
|
||
|
code: code,
|
||
|
expires: Date.vnNow() + maxTTL
|
||
|
}, myOptions);
|
||
|
return code;
|
||
|
};
|