Commit dcd2197d by 王悦

登录超时重置密码

parent 26d7e704
...@@ -103,8 +103,22 @@ class UserCtl extends CtlBase { ...@@ -103,8 +103,22 @@ class UserCtl extends CtlBase {
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 = 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 unlockUser(pobj, qobj, req) {
try {
await this.service.unlockUser(req.xctx.username)
return system.getResult({});
} catch (err) {
return system.getResult(null, err.message)
}
}
async getUserInfo(pobj, qobj, req) { 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);
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class LoginTimesCache extends CacheBase {
constructor() {
super();
}
isdebug() {
return settings.env == "dev";
}
desc() {
return "缓存登录错误次数信息";
}
prefix() {
return "g_login_times:"
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
if (val) {
return val;
}
return null;
}
async incrAsync(key) {
let cache = await this.getCache(key);
if (!cache) {
await this.cache(key, 0, 60 * 1000)
}
return this.redisClient.incr(key,)
}
}
module.exports = LoginTimesCache;
\ No newline at end of file
...@@ -134,6 +134,12 @@ class UserService extends ServiceBase { ...@@ -134,6 +134,12 @@ class UserService extends ServiceBase {
} }
}); });
} }
async unlockUser(username) {
let initpassword = this.getEncryptStr(settings.defaultpwd);
await this.resetPassword(username,initpassword);
return this.updateByWhere({ isEnabled: true }, { userName: username })
}
async logout(pobj) { async logout(pobj) {
await this.cacheManager["UserCache"].invalidate(pobj.username); await this.cacheManager["UserCache"].invalidate(pobj.username);
return {} return {}
...@@ -384,7 +390,7 @@ class UserService extends ServiceBase { ...@@ -384,7 +390,7 @@ class UserService extends ServiceBase {
//按照客户电话,建立和业务员的映射关系 //按照客户电话,建立和业务员的映射关系
//如果已经分配过,那么优先分配 //如果已经分配过,那么优先分配
/** /**
* *
* @param {*} clientMobile 客户电话 * @param {*} clientMobile 客户电话
* @param {*} spName 服务商名称 * @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称 * @param {*} productCatName 产品类型名称
...@@ -489,7 +495,7 @@ class UserService extends ServiceBase { ...@@ -489,7 +495,7 @@ class UserService extends ServiceBase {
return costAmount return costAmount
} }
/** /**
* *
* @param {*} clientMobile 客户电话 * @param {*} clientMobile 客户电话
* @param {*} spName 服务商名称 * @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称 * @param {*} productCatName 产品类型名称
......
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