Commit b1db0772 by Sxy

Merge branch 'center-manage' of gitlab.gongsibao.com:jiangyong/zhichan into center-manage

parents 61075a9c af8ef0e1
...@@ -7,23 +7,23 @@ class UserCtl extends CtlBase { ...@@ -7,23 +7,23 @@ class UserCtl extends CtlBase {
constructor() { constructor() {
super("auth", CtlBase.getServiceName(UserCtl)); super("auth", CtlBase.getServiceName(UserCtl));
} }
async logout(pobj, qobj, req) { async logout (pobj, qobj, req) {
let rtn = await this.service.logout(pobj) let rtn = await this.service.logout(pobj)
return system.getResult(rtn) return system.getResult(rtn)
} }
async pmgetUserByCode(pobj, qobj, req) { async pmgetUserByCode (pobj, qobj, req) {
let code = pobj.code let code = pobj.code
let rtn = await this.service.pmgetUserByCode(code) let rtn = await this.service.pmgetUserByCode(code)
return system.getResult(rtn) return system.getResult(rtn)
} }
async loginApp(pobj, qobj, req) { async loginApp (pobj, qobj, req) {
let appkey = pobj.fromAppKey let appkey = pobj.fromAppKey
let uname = pobj.username let uname = pobj.username
let rtn = await this.service.loginApp(appkey, uname) let rtn = await this.service.loginApp(appkey, uname)
return system.getResult(rtn); return system.getResult(rtn);
} }
async resetPassword(pobj, qobj, req) { async resetPassword (pobj, qobj, req) {
try { try {
await this.service.resetPassword(req.xctx.username, pobj.onepassword) await this.service.resetPassword(req.xctx.username, pobj.onepassword)
return system.getResult({}); return system.getResult({});
...@@ -31,15 +31,18 @@ class UserCtl extends CtlBase { ...@@ -31,15 +31,18 @@ class UserCtl extends CtlBase {
return system.getResult(null, err.message) return system.getResult(null, err.message)
} }
} }
async allowOrNot(pobj, qobj, req) { async allowOrNot (pobj, qobj, req) {
await this.service.updateByWhere({ isEnabled: !pobj.isEnabled }, { company_id: pobj.company_id }) await this.service.updateByWhere({ isEnabled: !pobj.isEnabled }, { company_id: pobj.company_id })
return system.getResult({}); return system.getResult({});
} }
async allowOrNotToOne(pobj, qobj, req) { async allowOrNotToOne (pobj, qobj, req) {
if (!pobj.isEnabled) {
await this.service.cacheManager["LoginTimesCache"].invalidate(pobj.userName)
}
await this.service.updateByWhere({ isEnabled: !pobj.isEnabled }, { id: pobj.curid }) await this.service.updateByWhere({ isEnabled: !pobj.isEnabled }, { id: pobj.curid })
return system.getResult({}); return system.getResult({});
} }
async initNewInstance(queryobj, req) { async initNewInstance (queryobj, req) {
var rtn = {}; var rtn = {};
rtn.roles = []; rtn.roles = [];
return system.getResultSuccess(rtn); return system.getResultSuccess(rtn);
...@@ -50,11 +53,11 @@ class UserCtl extends CtlBase { ...@@ -50,11 +53,11 @@ class UserCtl extends CtlBase {
// let v = await this.smsS.sendVCode(mobile); // let v = await this.smsS.sendVCode(mobile);
// return system.getResult({ vcodestr: v }); // return system.getResult({ vcodestr: v });
// } // }
async exit(pobj, qobj, req) { async exit (pobj, qobj, req) {
} }
//应用的自由用户注册,无需验证,需要前端头设置公司KEY //应用的自由用户注册,无需验证,需要前端头设置公司KEY
async pmregisterByFreeUser(p, q, req) { async pmregisterByFreeUser (p, q, req) {
//检查是否有用户名和密码 //检查是否有用户名和密码
if (!pobj.userName || !pobj.password) { if (!pobj.userName || !pobj.password) {
return system.getResult(null, "请检查用户名和密码是否存在") return system.getResult(null, "请检查用户名和密码是否存在")
...@@ -68,7 +71,7 @@ class UserCtl extends CtlBase { ...@@ -68,7 +71,7 @@ class UserCtl extends CtlBase {
return rtn; return rtn;
} }
async create(p, q, req) { async create (p, q, req) {
//检查是否有用户名和密码 //检查是否有用户名和密码
if (!p.userName) { if (!p.userName) {
return system.getResult(null, "请检查用户名和密码是否存在") return system.getResult(null, "请检查用户名和密码是否存在")
...@@ -81,7 +84,7 @@ class UserCtl extends CtlBase { ...@@ -81,7 +84,7 @@ class UserCtl extends CtlBase {
//和租户绑定同一家公司 //和租户绑定同一家公司
//按照用户名和密码进行注册 //按照用户名和密码进行注册
//控制器端检查用户名和密码非空 //控制器端检查用户名和密码非空
async registerByTantent(p, q, req) { async registerByTantent (p, q, req) {
//检查是否有用户名和密码 //检查是否有用户名和密码
if (!pobj.userName) { if (!pobj.userName) {
return system.getResult(null, "请检查用户名和密码是否存在") return system.getResult(null, "请检查用户名和密码是否存在")
...@@ -90,7 +93,7 @@ class UserCtl extends CtlBase { ...@@ -90,7 +93,7 @@ class UserCtl extends CtlBase {
return rtn; return rtn;
} }
//租户用户名和密码的租户注册 //租户用户名和密码的租户注册
async pmregister(pobj, qobj, req) { async pmregister (pobj, qobj, req) {
//平台注册设置平台的应用ID //平台注册设置平台的应用ID
pobj.app_id = settings.pmappid; pobj.app_id = settings.pmappid;
//检查是否有用户名和密码 //检查是否有用户名和密码
...@@ -100,19 +103,39 @@ class UserCtl extends CtlBase { ...@@ -100,19 +103,39 @@ class UserCtl extends CtlBase {
var rtn = await this.service.pmregister(pobj); var rtn = await this.service.pmregister(pobj);
return system.getResult(rtn); return system.getResult(rtn);
} }
async pmlogin(pobj, qobj, req) { async pmlogin (pobj, qobj, req) {
//平台注册设置平台的应用ID //平台注册设置平台的应用ID
let rtn = await this.service.pmlogin(pobj, qobj, req); let rtn = await this.service.pmlogin(pobj, qobj, req);
if (!rtn) {//登录错误
let times = await this.service.cacheManager["LoginTimesCache"].incrAsync(pobj.userName);
if (times >= 4) {
await this.service.updateByWhere({ isEnabled: false }, { userName: pobj.userName })
}
}
return system.getResult(rtn); return system.getResult(rtn);
} }
async getUserInfo(pobj, qobj, req) { /**
* 重置密码
* @param {*} pobj
* @param {*} qobj
* @param {*} req
*/
async unlockUser (pobj, qobj, req) {
try {
await this.service.unlockUser(pobj.userName)
return system.getResult({});
} catch (err) {
return system.getResult(null, err.message)
}
}
async getUserInfo (pobj, qobj, req) {
let uname = req.xctx.username; let uname = req.xctx.username;
let rtn = await this.service.getUserInfo(uname); let rtn = await this.service.getUserInfo(uname);
return system.getResult(rtn); return system.getResult(rtn);
} }
//按照电话创建自由用户 //按照电话创建自由用户
async pmloginByVCodeForFreeUser(p, q, req) { async pmloginByVCodeForFreeUser (p, q, req) {
if (!pobj.mobile || !pobj.vcode) { if (!pobj.mobile || !pobj.vcode) {
return system.getResult(null, "请检查手机号和验证码是否存在") return system.getResult(null, "请检查手机号和验证码是否存在")
} }
...@@ -123,11 +146,11 @@ class UserCtl extends CtlBase { ...@@ -123,11 +146,11 @@ class UserCtl extends CtlBase {
let rtn = await this.service.pmloginByVCodeForFreeUser(p, q); let rtn = await this.service.pmloginByVCodeForFreeUser(p, q);
return rtn; return rtn;
} }
async pmloginByVCode(pobj, qobj, req) { async pmloginByVCode (pobj, qobj, req) {
let rtn = await this.service.pmloginByVCode(pobj, qobj); let rtn = await this.service.pmloginByVCode(pobj, qobj);
return system.getResult(rtn); return system.getResult(rtn);
} }
async pmSendVCode(pobj, qobj, req) { async pmSendVCode (pobj, qobj, req) {
let rtn = await this.service.sendVCode(pobj, qobj); let rtn = await this.service.sendVCode(pobj, qobj);
return system.getResult(rtn); return system.getResult(rtn);
} }
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class LoginTimesCache extends CacheBase {
constructor() {
super();
}
isdebug () {
return false;
}
desc () {
return "缓存登录错误次数信息";
}
prefix () {
return "g_login_times:"
}
async buildCacheVal (cachekey, inputkey, val, ex, ...items) {
if (val) {
return val;
}
return null;
}
async incrAsync (key) {
let cachekey = this.prefix + key
let cache = await this.getCache(key);
if (!cache) {
await this.cache(key, 0, 60)
}
return this.redisClient.incr(cachekey)
}
}
module.exports = LoginTimesCache;
\ No newline at end of file
...@@ -9,11 +9,11 @@ class UserService extends ServiceBase { ...@@ -9,11 +9,11 @@ class UserService extends ServiceBase {
this.roleDao = system.getObject("db.auth.roleDao"); this.roleDao = system.getObject("db.auth.roleDao");
this.authS = system.getObject("service.auth.authSve"); this.authS = system.getObject("service.auth.authSve");
} }
async pmgetUserByCode(code) { async pmgetUserByCode (code) {
let ux = await this.cacheManager["CodeCache"].getCache(code); let ux = await this.cacheManager["CodeCache"].getCache(code);
return ux; return ux;
} }
async loginApp(appkey, uname) { async loginApp (appkey, uname) {
let rtn = {} let rtn = {}
let app = await this.cacheManager["AppCache"].cache(appkey); let app = await this.cacheManager["AppCache"].cache(appkey);
let userLogined = await this.cacheManager["UserCache"].cache(uname); let userLogined = await this.cacheManager["UserCache"].cache(uname);
...@@ -38,7 +38,7 @@ class UserService extends ServiceBase { ...@@ -38,7 +38,7 @@ class UserService extends ServiceBase {
//和租户绑定同一家公司 //和租户绑定同一家公司
//按照用户名和密码进行注册 //按照用户名和密码进行注册
//控制器端检查用户名和密码非空 //控制器端检查用户名和密码非空
async registerByTantent(p, q) { async registerByTantent (p, q) {
// 需要默认添加访客角色,为了控制单点从平台登录时看到的菜单和功能 // 需要默认添加访客角色,为了控制单点从平台登录时看到的菜单和功能
if (p.roles && p.roles.length > 0) { if (p.roles && p.roles.length > 0) {
if (p.roles.indexOf(settings.pmroleid["pr"]) < 0) { if (p.roles.indexOf(settings.pmroleid["pr"]) < 0) {
...@@ -51,7 +51,7 @@ class UserService extends ServiceBase { ...@@ -51,7 +51,7 @@ class UserService extends ServiceBase {
} }
//应用的自由用户注册,无需验证,需要前端头设置公司KEY //应用的自由用户注册,无需验证,需要前端头设置公司KEY
async pmregisterByFreeUser(p, q) { async pmregisterByFreeUser (p, q) {
p.rolecodes = [settings.pmroleid["pr"]]; p.rolecodes = [settings.pmroleid["pr"]];
let rtn = await this.pmregister(p, q) let rtn = await this.pmregister(p, q)
return rtn; return rtn;
...@@ -60,7 +60,7 @@ class UserService extends ServiceBase { ...@@ -60,7 +60,7 @@ class UserService extends ServiceBase {
//平台租户注册接口方法 //平台租户注册接口方法
//控制器端检查用户名和密码非空 //控制器端检查用户名和密码非空
async pmregister(p, q) { async pmregister (p, q) {
var self = this; var self = this;
let tmppwd = p.password; let tmppwd = p.password;
if (!tmppwd) { if (!tmppwd) {
...@@ -134,7 +134,12 @@ class UserService extends ServiceBase { ...@@ -134,7 +134,12 @@ class UserService extends ServiceBase {
} }
}); });
} }
async logout(pobj) { async unlockUser (username) {
await this.resetPassword(username, settings.defaultpwd);
return this.dao.updateByWhere({ isEnabled: true }, { userName: username })
}
async logout (pobj) {
await this.cacheManager["UserCache"].invalidate(pobj.username); await this.cacheManager["UserCache"].invalidate(pobj.username);
return {} return {}
} }
...@@ -142,7 +147,7 @@ class UserService extends ServiceBase { ...@@ -142,7 +147,7 @@ class UserService extends ServiceBase {
//登录接口封装kong-url //登录接口封装kong-url
//登录路由放行 //登录路由放行
//p里面含有appkey,company_id,userName,password //p里面含有appkey,company_id,userName,password
async pmlogin(p, q, req) { async pmlogin (p, q, req) {
var self = this; var self = this;
//先要按照用户名,在统一账户中查找存在性 //先要按照用户名,在统一账户中查找存在性
//如果不存在 //如果不存在
...@@ -186,7 +191,7 @@ class UserService extends ServiceBase { ...@@ -186,7 +191,7 @@ class UserService extends ServiceBase {
} }
}) })
} }
async getUserInfo(uname) { async getUserInfo (uname) {
// let userfind = await this.dao.model.findOne({ // let userfind = await this.dao.model.findOne({
// where: { userName: uname, app_id: settings.pmappid }, // where: { userName: uname, app_id: settings.pmappid },
// attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'], // attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'],
...@@ -207,7 +212,7 @@ class UserService extends ServiceBase { ...@@ -207,7 +212,7 @@ class UserService extends ServiceBase {
//自由用户的电话登录和注册 //自由用户的电话登录和注册
//需要存在公司KEY //需要存在公司KEY
async pmloginByVCodeForFreeUser(p, q) { async pmloginByVCodeForFreeUser (p, q) {
p.rolecodes = [settings.pmroleid["pr"]]; p.rolecodes = [settings.pmroleid["pr"]];
let rtn = await this.pmloginByVCode(p, q, req) let rtn = await this.pmloginByVCode(p, q, req)
return system.getResult(rtn); return system.getResult(rtn);
...@@ -216,7 +221,7 @@ class UserService extends ServiceBase { ...@@ -216,7 +221,7 @@ class UserService extends ServiceBase {
//平台租户注册与登录 //平台租户注册与登录
//用户验证码登录 //用户验证码登录
// //
async pmloginByVCode(p, q, req) { async pmloginByVCode (p, q, req) {
var rtn = {} var rtn = {}
//检查传递过来的手机验证码是否与缓存的一致 //检查传递过来的手机验证码是否与缓存的一致
let mobile = p.mobile; let mobile = p.mobile;
...@@ -261,19 +266,19 @@ class UserService extends ServiceBase { ...@@ -261,19 +266,19 @@ class UserService extends ServiceBase {
//不一致那么就 //不一致那么就
} }
//发送手机验证码并缓存 //发送手机验证码并缓存
async sendVCode(p, q, req) { async sendVCode (p, q, req) {
let mobile = p.mobile; let mobile = p.mobile;
let vcodeobj = await this.cacheManager["VCodeCache"].cache(mobile, null, 60); let vcodeobj = await this.cacheManager["VCodeCache"].cache(mobile, null, 60);
return vcodeobj.vcode; return vcodeobj.vcode;
} }
async reSendVCode(p, q, req) { async reSendVCode (p, q, req) {
let mobile = p.mobile; let mobile = p.mobile;
await this.cacheManager["VCodeCache"].invalidate(mobile); await this.cacheManager["VCodeCache"].invalidate(mobile);
let vcodeobj = await this.cacheManager["VCodeCache"].cache(mobile, null, 60); let vcodeobj = await this.cacheManager["VCodeCache"].cache(mobile, null, 60);
return vcodeobj.vcode; return vcodeobj.vcode;
} }
//修改中心密码 //修改中心密码
async cmodifypwd(uname, newpwd, cmpid) { async cmodifypwd (uname, newpwd, cmpid) {
try { try {
let rtn = await system.postJsonTypeReq(UserService.consumerUrl(uname), { tags: ["cmp_" + cmpid, "pass_" + newpwd] }, "PATCH") let rtn = await system.postJsonTypeReq(UserService.consumerUrl(uname), { tags: ["cmp_" + cmpid, "pass_" + newpwd] }, "PATCH")
console.log(rtn) console.log(rtn)
...@@ -287,7 +292,7 @@ class UserService extends ServiceBase { ...@@ -287,7 +292,7 @@ class UserService extends ServiceBase {
} }
} }
//创建统一账号及jwt身份 //创建统一账号及jwt身份
async cregister(uname, cmpid, pass, uid) { async cregister (uname, cmpid, pass, uid) {
try { try {
var rtn2 = null; var rtn2 = null;
let rtn = await system.postJsonTypeReq(UserService.newConsumerUrl(), { username: uname, custom_id: uid, tags: ["cmp_" + cmpid, "pass_" + pass] }) let rtn = await system.postJsonTypeReq(UserService.newConsumerUrl(), { username: uname, custom_id: uid, tags: ["cmp_" + cmpid, "pass_" + pass] })
...@@ -309,7 +314,7 @@ class UserService extends ServiceBase { ...@@ -309,7 +314,7 @@ class UserService extends ServiceBase {
} }
//plkey--对应消费者jwt身份的key,插件解码token后,获取iss-key,查询出身份,利用 //plkey--对应消费者jwt身份的key,插件解码token后,获取iss-key,查询出身份,利用
//身份中的secret验证签名 //身份中的secret验证签名
async jwtsign(plkey, secretstr, opts) { async jwtsign (plkey, secretstr, opts) {
let promise = new Promise(function (resv, rej) { let promise = new Promise(function (resv, rej) {
jwt.sign({ exp: Math.floor(Date.now() / 1000) + (60 * 60), iss: plkey }, secretstr, opts, function (err, rtn) { jwt.sign({ exp: Math.floor(Date.now() / 1000) + (60 * 60), iss: plkey }, secretstr, opts, function (err, rtn) {
if (err) { if (err) {
...@@ -322,13 +327,13 @@ class UserService extends ServiceBase { ...@@ -322,13 +327,13 @@ class UserService extends ServiceBase {
return promise; return promise;
} }
//只要登录 生成新的访问jwttoken //只要登录 生成新的访问jwttoken
async cmakejwt(key, secret, opts) { async cmakejwt (key, secret, opts) {
var token = await this.jwtsign(key, secret, opts); var token = await this.jwtsign(key, secret, opts);
return token; return token;
} }
//删除统一账号 //删除统一账号
async cunregister(uname) { async cunregister (uname) {
try { try {
let rtn = await system.delReq(UserService.consumerUrl(uname)) let rtn = await system.delReq(UserService.consumerUrl(uname))
if (rtn.statusCode == 204) { if (rtn.statusCode == 204) {
...@@ -342,15 +347,15 @@ class UserService extends ServiceBase { ...@@ -342,15 +347,15 @@ class UserService extends ServiceBase {
//登录统一账号 //登录统一账号
async clogin(uname) { async clogin (uname) {
//检查是否存在重名 //检查是否存在重名
} }
//按用户名查询统一用户 //按用户名查询统一用户
async findCUser(uname) { async findCUser (uname) {
} }
async resetPassword(uname, pwd) { async resetPassword (uname, pwd) {
let inpassword = this.getEncryptStr(pwd, true); let inpassword = this.getEncryptStr(pwd, true);
var self = this; var self = this;
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
...@@ -368,7 +373,7 @@ class UserService extends ServiceBase { ...@@ -368,7 +373,7 @@ class UserService extends ServiceBase {
}); });
} }
//修改 //修改
async update(qobj, tm = null) { async update (qobj, tm = null) {
var self = this; var self = this;
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
delete qobj['company_id'] delete qobj['company_id']
...@@ -384,13 +389,13 @@ class UserService extends ServiceBase { ...@@ -384,13 +389,13 @@ class UserService extends ServiceBase {
//按照客户电话,建立和业务员的映射关系 //按照客户电话,建立和业务员的映射关系
//如果已经分配过,那么优先分配 //如果已经分配过,那么优先分配
/** /**
* *
* @param {*} clientMobile 客户电话 * @param {*} clientMobile 客户电话
* @param {*} spName 服务商名称 * @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称 * @param {*} productCatName 产品类型名称
* @param {*} regionName 区域 * @param {*} regionName 区域
*/ */
async getBizUserForBizChance(clientMobile, spName, productCatName, regionName) { async getBizUserForBizChance (clientMobile, spName, productCatName, regionName) {
var self = this var self = this
clientMobile = clientMobile + "_" + spName + "_" + regionName + "_" + productCatName clientMobile = clientMobile + "_" + spName + "_" + regionName + "_" + productCatName
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称 //按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
...@@ -470,7 +475,7 @@ class UserService extends ServiceBase { ...@@ -470,7 +475,7 @@ class UserService extends ServiceBase {
} }
}) })
} }
async findCostBySkuCode(skucode) { async findCostBySkuCode (skucode) {
let productpricetmp = await this.db.models.productprice.findOne({ let productpricetmp = await this.db.models.productprice.findOne({
where: { skucode: skucode, isEnabled: true }, where: { skucode: skucode, isEnabled: true },
include: [ include: [
...@@ -489,14 +494,14 @@ class UserService extends ServiceBase { ...@@ -489,14 +494,14 @@ class UserService extends ServiceBase {
return costAmount return costAmount
} }
/** /**
* *
* @param {*} clientMobile 客户电话 * @param {*} clientMobile 客户电话
* @param {*} spName 服务商名称 * @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称 * @param {*} productCatName 产品类型名称
* @param {*} skucode 最小销售货品编码,来自渠道上架的码 * @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} regionName 区域 * @param {*} regionName 区域
*/ */
async getBizUserForDelivery(xclientMobile, spName, productCatName, skucode, regionName) { async getBizUserForDelivery (xclientMobile, spName, productCatName, skucode, regionName) {
let clientMobile = 'fordeliver' + xclientMobile + "_" + spName + "_" + regionName + "_" + productCatName let clientMobile = 'fordeliver' + xclientMobile + "_" + spName + "_" + regionName + "_" + productCatName
var self = this var self = this
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称 //按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
......
...@@ -19,7 +19,7 @@ var settings = { ...@@ -19,7 +19,7 @@ var settings = {
encrypt_key: ENVINPUT.ENCRYPT_KEY, encrypt_key: ENVINPUT.ENCRYPT_KEY,
encrypt_secret: ENVINPUT.ENCRYPT_SECRET, encrypt_secret: ENVINPUT.ENCRYPT_SECRET,
salt: "%iatpD1gcxz7iF#B", salt: "%iatpD1gcxz7iF#B",
defaultpwd: "gsb2020", defaultpwd: "Temp123456",
basepath: path.normalize(path.join(__dirname, '../..')), basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 80, port: process.env.NODE_PORT || 80,
logindex: "center_manage", logindex: "center_manage",
......
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