refs #6427 feat: move authCode method to file
This commit is contained in:
parent
f70b663ac0
commit
2ae298cd9e
|
@ -1,5 +1,6 @@
|
||||||
const ForbiddenError = require('vn-loopback/util/forbiddenError');
|
const ForbiddenError = require('vn-loopback/util/forbiddenError');
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const authCode = require('../../models/authCode');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('signIn', {
|
Self.remoteMethodCtx('signIn', {
|
||||||
|
@ -65,16 +66,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.sendTwoFactor = async(ctx, vnUser, myOptions) => {
|
Self.sendTwoFactor = async(ctx, vnUser, myOptions) => {
|
||||||
if (vnUser.twoFactor === 'email') {
|
if (vnUser.twoFactor === 'email') {
|
||||||
const $ = Self.app.models;
|
const code = await authCode(vnUser, myOptions);
|
||||||
|
|
||||||
const code = String(Math.floor(Math.random() * 999999));
|
|
||||||
const maxTTL = ((60 * 1000) * 5); // 5 min
|
|
||||||
await $.AuthCode.upsertWithWhere({userFk: vnUser.id}, {
|
|
||||||
userFk: vnUser.id,
|
|
||||||
code: code,
|
|
||||||
expires: Date.vnNow() + maxTTL
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const headers = ctx.req.headers;
|
const headers = ctx.req.headers;
|
||||||
const platform = headers['sec-ch-ua-platform']?.replace(/['"=]+/g, '');
|
const platform = headers['sec-ch-ua-platform']?.replace(/['"=]+/g, '');
|
||||||
const browser = headers['sec-ch-ua']?.replace(/['"=]+/g, '');
|
const browser = headers['sec-ch-ua']?.replace(/['"=]+/g, '');
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
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;
|
||||||
|
};
|
Loading…
Reference in New Issue