Commit 337cf2a9 by 宋毅

tj

parent b16f2e25
...@@ -29,11 +29,11 @@ class AccessAuthAPI extends APIBase { ...@@ -29,11 +29,11 @@ class AccessAuthAPI extends APIBase {
var result = await this.opPlatformUtils.getReqUserPinByLgoin(pobj); var result = await this.opPlatformUtils.getReqUserPinByLgoin(pobj);
return result; return result;
} }
async getUserPinByChannelUserId(pobj, qobj, req) {//通过账户获取用户信息----------------------------actionBody.channelUserId async getLoginByUserName(pobj, qobj, req) {//通过账户获取用户信息----------------------------actionBody.channelUserId
if (!pobj.actionBody.channelUserId) { if (!pobj.actionBody.channelUserId) {
return system.getResult(null, "actionBody.channelUserId can not be empty !"); return system.getResult(null, "actionBody.channelUserId can not be empty !");
} }
var result = await this.opPlatformUtils.getUserPinByChannelUserId(pobj); var result = await this.opPlatformUtils.getLoginByUserName(pobj);
return result; return result;
} }
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class AppUserPinByChannelUserIdCache extends CacheBase {
constructor() {
super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
this.restClient = system.getObject("util.restClient");
this.appuserDao = system.getObject("db.dbapp.appuserDao");
}
desc() {
return "应用中缓存访问token";
}
prefix() {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val.actionBody;
var appInfo = val.appInfo;
var createUserPwd = inputkey;//(格式:appInfo.uapp_key+”_“+actionBody.channelUserId)
var channelUserMoblie = actionBody.mobile ? actionBody.mobile : actionBody.channelUserId;
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.channelUserId, appInfo.uapp_id);
if (userInfo) {
if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !");
}
userInfo.userpin = actionBody.userpin;
return system.getResultSuccess(userInfo);
}
var uUserInfo = await this.opPlatformUtils.createUserInfo(actionBody.channelUserId, channelUserMoblie,
createUserPwd, appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 2000 && uUserInfo.status != 0) {
return uUserInfo;
}//2000已经存在此用户 或 注册失败
if (uUserInfo.status == 0) {
var params = {
uapp_id: appInfo.uapp_id,
channel_userid: actionBody.channelUserId,
channel_username: actionBody.channelUserName || actionBody.channelUserId,
channel_nickname: actionBody.nickName || "",
mobile: channelUserMoblie,
org_name: actionBody.orgName || "",
org_path: actionBody.orgPath || "",
is_enabled: 1,
email: actionBody.email || "",
last_login_time: new Date()
};
userInfo = await this.appuserDao.create(params);
}
userInfo.userpin = actionBody.userpin;
return system.getResultSuccess(userInfo);
}
}
module.exports = AppUserPinByChannelUserIdCache;
...@@ -16,14 +16,10 @@ class AppUserPinByUserNameCache extends CacheBase { ...@@ -16,14 +16,10 @@ class AppUserPinByUserNameCache extends CacheBase {
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val.actionBody; var actionBody = val.actionBody;
var appInfo = val.appInfo; var appInfo = val.appInfo;
var uUserName = actionBody.userName;//uUserName var uUserName = actionBody.userName ? actionBody.userName : actionBody.channelUserId;
var uPassword = actionBody.userName;//uPassword var uPassword = actionBody.userName;//uPassword
var mobile = actionBody.mobile;//uPassword var mobile = actionBody.mobile ? actionBody.mobile : actionBody.channelUserId;
var uUserInfo = await this.opPlatformUtils.register(uUserName, uPassword, mobile,
appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 0 && uUserInfo.status != 2000) {
return uUserInfo;
}//值为2000为已经存在此用户,注册失败
var userInfo = await this.appuserDao.getItemByChannelUserId(uUserName, appInfo.uapp_id); var userInfo = await this.appuserDao.getItemByChannelUserId(uUserName, appInfo.uapp_id);
if (userInfo) { if (userInfo) {
if (userInfo.is_enabled != 1) { if (userInfo.is_enabled != 1) {
...@@ -32,12 +28,17 @@ class AppUserPinByUserNameCache extends CacheBase { ...@@ -32,12 +28,17 @@ class AppUserPinByUserNameCache extends CacheBase {
userInfo.userpin = actionBody.userpin; userInfo.userpin = actionBody.userpin;
return system.getResultSuccess(userInfo); return system.getResultSuccess(userInfo);
} }
var uUserInfo = await this.opPlatformUtils.register(uUserName, uPassword, mobile,
appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 0 && uUserInfo.status != 2000) {
return uUserInfo;
}//值为2000为已经存在此用户,注册失败
var params = { var params = {
uapp_id: appInfo.uapp_id, uapp_id: appInfo.uapp_id,
channel_userid: uUserName || "", channel_userid: actionBody.channelUserId || "",
channel_username: uUserName || "", channel_username: uUserName || "",
channel_nickname: actionBody.nickName || "", channel_nickname: actionBody.nickName || "",
mobile: actionBody.mobile || "", mobile: mobile || "",
org_name: actionBody.orgName || "", org_name: actionBody.orgName || "",
org_path: actionBody.orgPath || "", org_path: actionBody.orgPath || "",
is_enabled: 1, is_enabled: 1,
......
...@@ -299,10 +299,10 @@ class OpPlatformUtils { ...@@ -299,10 +299,10 @@ class OpPlatformUtils {
* 渠道通过账户进行登录,有则返回用户信息,没有则创建用户---actionBody.channelUserId * 渠道通过账户进行登录,有则返回用户信息,没有则创建用户---actionBody.channelUserId
* @param {*} pobj pobj.actionBody:{channelUserId:XX} * @param {*} pobj pobj.actionBody:{channelUserId:XX}
*/ */
async getUserPinByChannelUserId(pobj) { async getLoginByUserName(pobj) {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.channelUserId; var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.channelUserId;
var cacheManager = system.getObject("db.common.cacheManager"); var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByChannelUserIdCache"].getCache(inputkey); var result = await cacheManager["AppUserPinByUserNameCache"].getCache(inputkey);
if (result && result.status == 0) { if (result && result.status == 0) {
if (result.data.userpin) { if (result.data.userpin) {
return system.getResultFail(system.reDoLoginFail, "请勿重复处理", { userpin: result.data.userpin || "" }); return system.getResultFail(system.reDoLoginFail, "请勿重复处理", { userpin: result.data.userpin || "" });
...@@ -310,7 +310,7 @@ class OpPlatformUtils { ...@@ -310,7 +310,7 @@ class OpPlatformUtils {
await this.clearLoginCache(inputkey); await this.clearLoginCache(inputkey);
} }
} }
var result = await cacheManager["AppUserPinByChannelUserIdCache"].cache(inputkey, pobj, system.shortExTime); var result = await cacheManager["AppUserPinByUserNameCache"].cache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) { if (result && result.status == 0) {
var userpinKey = this.getUserPinKey(pobj.actionBody.userpin); var userpinKey = this.getUserPinKey(pobj.actionBody.userpin);
this.redisClient.setWithEx(userpinKey, JSON.stringify(result), system.exTime); this.redisClient.setWithEx(userpinKey, JSON.stringify(result), system.exTime);
...@@ -412,7 +412,6 @@ class OpPlatformUtils { ...@@ -412,7 +412,6 @@ class OpPlatformUtils {
await cacheManager["AppUserPinByLoginPwdCache"].invalidate(inputkey); await cacheManager["AppUserPinByLoginPwdCache"].invalidate(inputkey);
await cacheManager["AppUserPinByLoginVcodeCache"].invalidate(inputkey); await cacheManager["AppUserPinByLoginVcodeCache"].invalidate(inputkey);
await cacheManager["AppUserPinByUserNameCache"].invalidate(inputkey); await cacheManager["AppUserPinByUserNameCache"].invalidate(inputkey);
await cacheManager["AppUserPinByChannelUserIdCache"].invalidate(inputkey);
} }
} }
......
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