84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
const Service = require('../core/base_service');
|
||
|
|
|
||
|
|
const fileName = "verify";
|
||
|
|
|
||
|
|
// const sha256 = require("crypto-js/sha256");
|
||
|
|
|
||
|
|
const { Op } = require("sequelize");
|
||
|
|
|
||
|
|
class VerifyService extends Service {
|
||
|
|
async toLogin(origin_url) {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
// const temporary = sha256(sha256(this.generateRandomString()).toString()+'temporary').toString();
|
||
|
|
// Op.regexp 正则匹配,适用于不同端用户登录同一域名的网站
|
||
|
|
// await ctx.model.Business.update({ temporary_id: temporary }, { where: { client_url: { [Op.regexp]: origin_url } } });
|
||
|
|
// const result = await ctx.model.Business.findOne({ where: { client_url: { [Op.regexp]: origin_url } } });
|
||
|
|
// Op.startsWith 包含,适用于不同端用户登录不同域名网站
|
||
|
|
// await ctx.model.Business.update({ temporary_id: temporary }, { where: { client_url: { [Op.startsWith]: origin_url } } });
|
||
|
|
const where = { client_url: { [Op.startsWith]: origin_url } };
|
||
|
|
const result = await ctx.model3.Business.findOne({ where });
|
||
|
|
return result || false;
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "toLogin";
|
||
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||
|
|
return 'error';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async loginClient(client_id) {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
let checkFixedClient = false;
|
||
|
|
ctx.app.config.fixedClient.forEach(element => {
|
||
|
|
if (client_id == element) checkFixedClient = true;
|
||
|
|
});
|
||
|
|
if (checkFixedClient) {
|
||
|
|
return {
|
||
|
|
dataValues: {
|
||
|
|
client_id,
|
||
|
|
client_secret: client_id
|
||
|
|
}
|
||
|
|
};
|
||
|
|
} else {
|
||
|
|
const where = { temporary_id: client_id };
|
||
|
|
const result = await ctx.model3.Business.findOne({ where });
|
||
|
|
return result || false;
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "loginClient";
|
||
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||
|
|
return 'error';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async getToken(client_id) {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
let checkFixedClient = false;
|
||
|
|
ctx.app.config.fixedClient.forEach(element => {
|
||
|
|
if (client_id == element) checkFixedClient = true;
|
||
|
|
});
|
||
|
|
if (checkFixedClient) {
|
||
|
|
return {
|
||
|
|
dataValues: {
|
||
|
|
client_id,
|
||
|
|
client_secret: client_id
|
||
|
|
}
|
||
|
|
};
|
||
|
|
} else {
|
||
|
|
const where = { client_id };
|
||
|
|
const result = await ctx.model3.Business.findOne({ where });
|
||
|
|
return result || false;
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "getToken";
|
||
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||
|
|
return 'error';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = VerifyService;
|