Commit b60b65d1 by 王悦

add tx_uin 验证码登录

parent 32455d75
......@@ -6,6 +6,7 @@ const CtlBase = require("../../ctl.base");
class UserCtl extends CtlBase {
constructor() {
super("auth", CtlBase.getServiceName(UserCtl));
this.captchaSve = system.getObject("service.auth.captchaSve");
}
async logout (pobj, qobj, req) {
let rtn = await this.service.logout(pobj)
......@@ -105,6 +106,9 @@ class UserCtl extends CtlBase {
}
async pmlogin (pobj, qobj, req) {
//平台注册设置平台的应用ID
let verifyres = await this.captchaSve.apiValidator({key:pobj.key,code:pobj.code});
if (verifyres.status !== 0)
return verifyres;
let rtn = await this.service.pmlogin(pobj, qobj, req);
let msg = null
if (!rtn) {//登录错误
......@@ -158,6 +162,10 @@ class UserCtl extends CtlBase {
let rtn = await this.service.sendVCode(pobj, qobj);
return system.getResult(rtn);
}
async pmPicVerifyCode (pobj, qobj, req) {
let rtn = await this.captchaSve.apiGenerate(pobj, qobj);
return system.getResult(rtn);
}
}
module.exports = UserCtl;
......@@ -8,7 +8,7 @@ class UserCache extends CacheBase {
this.channelDao = system.getObject("db.common.channelDao");
}
isdebug() {
return settings.env == "dev";
return settings.env == "localhost";
}
desc() {
return "缓存本地应用对象";
......@@ -19,7 +19,7 @@ class UserCache extends CacheBase {
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
const configValue = await this.userDao.model.findAll({
where: { userName: inputkey, app_id: settings.pmappid, isEnabled: true },
attributes: ['id', 'userName', 'nickName', 'headUrl', 'jwtkey', 'jwtsecret', 'created_at', 'isSuper', 'isAdmin', 'isAllocated', 'mail', 'mobile', 'opath', 'ptags'],
attributes: ['id', 'userName', 'nickName', 'headUrl', 'jwtkey', 'jwtsecret', 'created_at', 'isSuper', 'isAdmin', 'isAllocated', 'mail', 'mobile', 'opath', 'ptags','tx_uin'],
include: [
{ model: this.db.models.company, attributes: ['id', 'name', 'companykey', 'appids', "code"], raw: true },
{ model: this.db.models.role, as: "Roles", attributes: ["id", "code"], }
......
......@@ -47,7 +47,6 @@ module.exports = (db, DataTypes) => {
},
last_change_date: {
type: DataTypes.DATE,
defaultValue: false
},
isSuper: {
type: DataTypes.BOOLEAN,
......@@ -79,6 +78,9 @@ module.exports = (db, DataTypes) => {
type: DataTypes.STRING,
allowNull: true,
},
tx_uin: {
type: DataTypes.STRING,
},
isDelivery: {
type: DataTypes.BOOLEAN,
defaultValue: false
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
class CaptchaService {
constructor() {
this.redisClient = system.getObject("util.redisClient");
}
async apiGenerate(params) {
var key = uuidv4();
var options = {
size: 4,
noise: 1,
ignoreChars: '0o1iILl'
};
options.width = this.trim(params.width) || 120;
options.height = this.trim(params.height) || 32;
options.background = this.trim(params.background) || "#E8E8E8";
var captchaPrev = this.trim(params.captchaPrev);
var expire = Number(params.expire || 3 * 60)
try {
var cap = svgCaptcha.create(options);
console.log(cap);
await this.redisClient.setWithEx(key, cap.text, expire);
return system.getResultSuccess({
key: key,
text: cap.text,
captcha: cap.data,
});
} catch (error) {
return system.getResult(null, "接口异常:" + error.message);
}
}
async apiValidator(params) {
var key = this.trim(params.key);
var code = this.trim(params.code);
var cacheCode = await this.redisClient.get(key);
if(!cacheCode) {
return system.getResult(null, "验证码已过期,请点击重试");
}
if(code.toLowerCase() != cacheCode.toLowerCase()) {
await this.redisClient.delete(key);
return system.getResult(null, "验证码输入错误,清点击重试");
}
return system.getResultSuccess(1);
}
trim(o) {
if(!o) {
return "";
}
return o.toString().trim();
}
}
module.exports = CaptchaService;
\ No newline at end of file
......@@ -429,7 +429,7 @@ class UserService extends ServiceBase {
let companyFind = await self.companyDao.model.findOne({
where: { name: spName }, include: [
{
model: self.db.models.user, as: "us", attributes: ['id', 'userName', 'mobile', 'isAllocated', 'opath', 'skilltags', 'regiontags', 'isAllArea', 'isSalesman', 'isDelivery'], raw: true
model: self.db.models.user, as: "us", attributes: ['id', 'userName', 'mobile', 'isAllocated', 'opath', 'skilltags', 'regiontags', 'isAllArea', 'isSalesman', 'isDelivery','tx_uin'], raw: true
}
], excludes: ['orgJson'], transaction: t
});
......@@ -539,7 +539,7 @@ class UserService extends ServiceBase {
let companyFind = await self.companyDao.model.findOne({
where: { name: spName }, include: [
{
model: self.db.models.user, as: "us", attributes: ['id', 'userName', 'mobile', 'isAllocated', 'opath', 'skilltags', 'regiontags', 'isAllArea', 'isSalesman', 'isDelivery'], raw: true
model: self.db.models.user, as: "us", attributes: ['id', 'userName', 'mobile', 'isAllocated', 'opath', 'skilltags', 'regiontags', 'isAllArea', 'isSalesman', 'isDelivery','tx_uin'], raw: true
}
], excludes: ['orgJson'], transaction: t
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment