Commit baec1ffa by 宋毅

tj

parent bd73a0e1
...@@ -29,6 +29,13 @@ class AccessAuthAPI extends APIBase { ...@@ -29,6 +29,13 @@ class AccessAuthAPI extends APIBase {
var result = await this.opPlatformUtils.getReqUserPinByLgoin(pobj); var result = await this.opPlatformUtils.getReqUserPinByLgoin(pobj);
return result; return result;
} }
async getLoginByUserName(pobj, qobj, req) {//通过账户获取用户信息----------------------------actionBody.userName
if (!pobj.actionBody.userName) {
return system.getResult(null, "actionBody.userName can not be empty !");
}
var result = await this.opPlatformUtils.getLoginByUserName(pobj);
return result;
}
async loginByVerifyCode(pobj, qobj, req) {//通过短信登录或注册信息 async loginByVerifyCode(pobj, qobj, req) {//通过短信登录或注册信息
if (!pobj.actionBody.mobile) { if (!pobj.actionBody.mobile) {
......
...@@ -13,9 +13,7 @@ class ApiAccessKeyCache extends CacheBase { ...@@ -13,9 +13,7 @@ class ApiAccessKeyCache extends CacheBase {
return settings.cacheprefix + "_accesskey:"; return settings.cacheprefix + "_accesskey:";
} }
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var appkey = inputkey || settings.appKey; var acckapp = await this.restS.execPost({ appkey: val.appkey, secret: val.secret }, settings.paasUrl() + "api/auth/accessAuth/getAccessKey");
var secret = items && items.length > 0 ? items[0] : settings.secret;
var acckapp = await this.restS.execPost({ appkey: appkey, secret: secret }, settings.paasUrl() + "api/auth/accessAuth/getAccessKey");
var s = acckapp.stdout; var s = acckapp.stdout;
console.log(acckapp.stdout, "ApiAccessKeyCache............. acckapp.stdout..........") console.log(acckapp.stdout, "ApiAccessKeyCache............. acckapp.stdout..........")
if (s) { if (s) {
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class AppUserPinByUserNameCache extends CacheBase {
constructor() {
super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
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 uUserName = actionBody.userName;//uUserName
var uPassword = actionBody.userName;//uPassword
var mobile = actionBody.mobile;//uPassword
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);
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 params = {
uapp_id: appInfo.uapp_id,
channel_userid: uUserName || "",
channel_username: uUserName || "",
channel_nickname: actionBody.nickName || "",
mobile: actionBody.mobile || "",
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 = AppUserPinByUserNameCache;
...@@ -16,7 +16,6 @@ class AppService extends ServiceBase { ...@@ -16,7 +16,6 @@ class AppService extends ServiceBase {
} }
var acckapp = await this.restS.execPost({ appkey: appkey, secret: secret }, settings.paasUrl() + "api/auth/accessAuth/getAccessKey"); var acckapp = await this.restS.execPost({ appkey: appkey, secret: secret }, settings.paasUrl() + "api/auth/accessAuth/getAccessKey");
var s = acckapp.stdout; var s = acckapp.stdout;
console.log(acckapp.stdout, "ApiAccessKeyCache............. acckapp.stdout..........")
if (s) { if (s) {
var tmp = JSON.parse(s); var tmp = JSON.parse(s);
return tmp; return tmp;
......
...@@ -11,6 +11,7 @@ class OpPlatformUtils { ...@@ -11,6 +11,7 @@ class OpPlatformUtils {
this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode"; this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode";
this.fetchOtherVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchOtherVCode"; this.fetchOtherVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchOtherVCode";
this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/login"; this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/login";
this.registerUrl = settings.paasUrl() + "api/auth/accessAuth/register";
this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode"; this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode";
this.modiPasswordByMobileUrl = settings.paasUrl() + "api/auth/accessAuth/modiPasswordByMobile"; this.modiPasswordByMobileUrl = settings.paasUrl() + "api/auth/accessAuth/modiPasswordByMobile";
} }
...@@ -24,12 +25,15 @@ class OpPlatformUtils { ...@@ -24,12 +25,15 @@ class OpPlatformUtils {
} }
async getReqApiAccessKey(appKey, secret) { async getReqApiAccessKey(appKey, secret) {
var cacheManager = system.getObject("db.common.cacheManager"); var cacheManager = system.getObject("db.common.cacheManager");
var reqApiAccessKey = null; var inputkeyStr = settings.cacheprefix + "_platformToken:appKey_" + settings.appKey;;
var secretInfo = { appkey: settings.appKey, secret: settings.secret };
if (appKey && secret) { if (appKey && secret) {
reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(appKey, null, system.exTime, secret); inputkeyStr = settings.cacheprefix + "_platformToken:appKey_" + appKey;
} else { secretInfo.appkey = appKey;
reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, system.exTime); secretInfo.secret = secret;
} }
var reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(inputkeyStr, secretInfo, system.exTime);
if (!reqApiAccessKey || !reqApiAccessKey.data) { if (!reqApiAccessKey || !reqApiAccessKey.data) {
return system.getResult(null, "获取请求token失败"); return system.getResult(null, "获取请求token失败");
} }
...@@ -178,6 +182,43 @@ class OpPlatformUtils { ...@@ -178,6 +182,43 @@ class OpPlatformUtils {
"requestid": "5362bf6f941e4f92961a61068f05cd7f" "requestid": "5362bf6f941e4f92961a61068f05cd7f"
} }
*/ */
async register(userName, password, mobile, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) {
return reqApiAccessKey;
}
var param = {
userName: userName,
password: password || settings.defaultPassWord,
mobile: mobile
}
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.registerUrl, reqApiAccessKey.data.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResultFail(restResult.status, restResult.msg);
}
return system.getResultSuccess(restResult.data);
}
/**
* 用户登录
* @param {*} userName 用户名
* @param {*} password 密码,不传为使用默认密码
*
* 返回值:
* {
"status": 0,---值为2010为用户名或密码错误
"msg": "success",
"data": {
"auth_url": "http://sj.app.com:3002/auth?opencode=1e4949d1c39444a8b32f023143625b1d",---回调url,通过回调地址获取平台用户信息
"opencode": "1e4949d1c39444a8b32f023143625b1d"---平台用户code随机生成会变,平台是30s有效期,通过其可以向获取用户信息
},
"requestid": "5362bf6f941e4f92961a61068f05cd7f"
}
*/
async login(userName, password, appKey, secret) { async login(userName, password, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret); var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) { if (reqApiAccessKey.status != 0) {
...@@ -280,6 +321,30 @@ class OpPlatformUtils { ...@@ -280,6 +321,30 @@ class OpPlatformUtils {
// var result = await cacheManager["AppUserPinByChannelUserId"].cache(userPinValue, actionBody, system.exTime); // var result = await cacheManager["AppUserPinByChannelUserId"].cache(userPinValue, actionBody, system.exTime);
// return result; // return result;
// } // }
/**
* 通过账户和密码登录
* @param {*} pobj pobj.actionBody:{userName:XX}
*/
async getLoginByUserName(pobj) {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.userName;
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByUserNameCache"].getCache(inputkey);
if (result && result.status == 0) {
if (result.data.userpin) {
return system.getResultFail(system.reDoLoginFail, "请勿重复登录", { userpin: result.data.userpin || "" });
}else{
await cacheManager["AppUserPinByLoginPwdCache"].invalidate(inputkey);
await cacheManager["AppUserPinByLoginVcodeCache"].invalidate(inputkey);
await cacheManager["AppUserPinByUserNameCache"].invalidate(inputkey);
}
}
var result = await cacheManager["AppUserPinByUserNameCache"].cache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) {
var userpinKey = this.getUserPinKey(pobj.actionBody.userpin);
this.redisClient.setWithEx(userpinKey, JSON.stringify(result), system.exTime);
}
return result;
}
/** /**
* 通过账户和密码登录 * 通过账户和密码登录
...@@ -368,6 +433,7 @@ class OpPlatformUtils { ...@@ -368,6 +433,7 @@ class OpPlatformUtils {
var cacheManager = system.getObject("db.common.cacheManager"); var cacheManager = system.getObject("db.common.cacheManager");
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);
} }
this.redisClient.delete(userpinKey); this.redisClient.delete(userpinKey);
return system.getResultSuccess();; return system.getResultSuccess();;
......
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