Commit 94f6e74c by 宋毅

tj

parent ea19ea0a
......@@ -4,7 +4,6 @@ class AccessAuthAPI extends APIBase {
constructor() {
super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
}
/**
* 接口跳转-POST请求
......@@ -40,40 +39,38 @@ class AccessAuthAPI extends APIBase {
async opActionProcess(action_process, action_type, action_body, req) {
var opResult = system.getResult(null, "req Failure");
var userpin = this.getUUID();
action_body.appInfo = req.appInfo;
action_body.appInfo = req.app;
switch (action_type) {
// sy
case "test"://测试
opResult = system.getResultSuccess(null, "测试成功");
break;
case "getVerifyCode":
opResult = await this.opPlatformUtils.getVerifyCodeByMoblie(action_body, action_process, req);
opResult = await this.opPlatformUtils.getVerifyCodeByMoblie(action_body);
if (opResult.status == 0) {
return system.getResultSuccess()
}
break;
case "loginUserByChannelUserId":
opResult = await this.utilsAuthSve.loginUserByChannelUserId(action_body, action_process, userpin, req);
case "loginUserByChannelUserId"://????
opResult = await this.opPlatformUtils.loginUserByChannelUserId(action_body, action_process, userpin, req);
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin })
}
break;
case "userPinByLgoin":
opResult = await this.utilsAuthSve.getReqUserPinByLgoin(action_body, action_process, userpin, req);
opResult = await this.opPlatformUtils.getReqUserPinByLgoin(action_body, userpin);
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin })
}
break;
case "userPinByLgoinVcode":
action_body.reqType = "login";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(action_body, action_process, userpin, req);
opResult = await this.opPlatformUtils.getReqUserPinByLgoinVcode(action_body, userpin, "login");
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin })
}
break;
case "userPinByRegister":
action_body.reqType = "reg";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(action_body, action_process, userpin, req);
opResult = await this.opPlatformUtils.getReqUserPinByLgoinVcode(action_body, userpin, "reg");
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin })
}
......
......@@ -15,13 +15,22 @@ class AppUserPinByLoginPwdCache extends CacheBase {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var acckapp = await this.restClient.execPost(val, settings.centerAppUrl() + "auth/accessAuth/login");
var result = acckapp.stdout;
if (result) {
var tmp = JSON.parse(result);
return tmp;
var actionBody = val;
var uUserName = actionBody.userName;//uUserName
var uPassword = actionBody.password;//uPassword
var uUserInfo = await this.opPlatformUtils.login(uUserName, uPassword,
actionBody.appInfo.uapp_key, actionBody.appInfo.uapp_secret);
if (uUserInfo.status != 0) {
return uUserInfo;
}//值为2010为用户名或密码错误
var userInfo = await this.appuserDao.getItemByUUserId(actionBody.userName, actionBody.appInfo.id);
if (!userInfo) {
return system.getResult(null, "user to item is empty !");
}
return system.getResult(null, "data is empty");
if (userInfo.isEnabled != 1) {
return system.getResult(null, "user to item is Disable !");
}
return system.getResultSuccess(userInfo);
}
}
module.exports = AppUserPinByLoginPwdCache;
......@@ -15,13 +15,36 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var acckapp = await this.restClient.execPost(val, settings.centerAppUrl() + "auth/accessAuth/loginByVerifyCode");
var result = acckapp.stdout;
if (result) {
var tmp = JSON.parse(result);
return tmp;
var actionBody = val;
var uUserInfo = await this.opPlatformUtils.loginByVCode(actionBody.mobile, actionBody.vcode, actionBody.password,
actionBody.appInfo.uapp_key, actionBody.appInfo.uapp_secret);
if (uUserInfo.status != 0) {
return uUserInfo;
}//2030验证码校验不成功 或 注册失败
var userInfo = await this.appuserDao.getItemByUUserId(actionBody.userName, actionBody.appInfo.id);
if (userInfo) {
if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !");
}
return system.getResultSuccess(userInfo);
}
return system.getResult(null, "data is empty");
var params = {
app_id: actionBody.appInfo.id,
channelUserId: actionBody.mobile || "",
channelUserName: actionBody.mobile || "",
userMoblie: actionBody.mobile || "",
nickname: actionBody.nickName || "",
orgName: actionBody.orgName || "",
orgPath: actionBody.orgPath || "",
uUserName: actionBody.mobile || "",
uAppId: actionBody.appInfo.uAppId,
isEnabled: 1,
lastLoginTime: new Date()
};
userInfo = await this.appuserDao.create(params);
return system.getResultSuccess(userInfo);
}
}
module.exports = AppUserPinByLoginVcodeCache;
var system = require("../../../system");
var settings = require("../../../../config/settings");
const logCtl = system.getObject("service.common.oplogSve");
//商标查询操作
class UtilsAuthSve {
constructor() {
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
}
async loginUserByChannelUserId(action_body, action_process, userpin, req) {
var opResult = null;
switch (action_process) {
case "gsbhome":
opResult = await this.getDefaultUserInfo(action_body, userpin);
break;
default:
opResult = system.getResult(null, "action_process参数错误");
break;
}
return opResult;
}
async getDefaultUserInfo(action_body, userpin) {
var userinfo = await this.opPlatformUtils.getReqUserPinByChannelUserId(action_body, userpin);
return userinfo;
}
//---------------登录-----------------------------------------------------
async getReqUserPinByLgoin(action_body, action_process, userpin, req) {
var userinfo = await this.opPlatformUtils.getReqUserPinByLgoin(action_body, userpin);
return userinfo;
}
async getReqUserPinByLgoinVcode(action_body, action_process, userpin, req) {
var userinfo = await this.opPlatformUtils.getReqUserPinByLgoinVcode(action_body, userpin, action_body.reqType);
return userinfo;
}
}
module.exports = UtilsAuthSve;
......@@ -10,6 +10,7 @@ class OpPlatformUtils {
this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode";
this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/loginByMd5Password";
this.authByCodeUrl = settings.paasUrl() + "api/auth/accessAuth/authByCode";
this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode";
this.exTime = 2 * 3600;//缓存过期时间,2小时
}
getUUID() {
......@@ -69,8 +70,8 @@ class OpPlatformUtils {
}
return system.getResultSuccess(restResult.data);
}
async fetchVCode(mobile) {
var reqApiAccessKey = await this.getReqApiAccessKey(null, null);
async fetchVCode(mobile, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) {
return reqApiAccessKey;
}
......@@ -151,7 +152,40 @@ class OpPlatformUtils {
}
return system.getResultSuccess(restResult.data);
}
/**
* 创建用户信息
* @param {*} userName 用户名
* @param {*} mobile 手机号
* @param {*} password 密码,不传为使用默认密码
*
* 返回值:
* {
"status": 0,---值为2000为已经存在此用户,注册失败
"msg": "success",
"data": {
"auth_url": "http://sj.app.com:3002/auth?opencode=1e4949d1c39444a8b32f023143625b1d",---回调url,通过回调地址获取平台用户信息
"opencode": "1e4949d1c39444a8b32f023143625b1d",---平台用户code随机生成会变,平台是30s有效期,通过其可以向获取用户信息
"open_user_id": 12---平台用户id
},
"requestid": "5362bf6f941e4f92961a61068f05cd7f"
}
*/
async loginByVCode(mobile, vcode, password, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) {
return reqApiAccessKey;
}
var param = {
mobile: mobile,
vcode: vcode,
password: password || ""
}
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.loginByVCodeUrl, reqApiAccessKey.data.accessKey);
return restResult;
}
//------------------------新的方式------------------------------------------------------------------------------------
async getReqTokenByHosts(appHosts, tokenValue) {
if (!appHosts) {
......@@ -203,13 +237,11 @@ class OpPlatformUtils {
if (!actionBody.mobile) {
return system.getResult(null, "pobj.mobile can not be empty !");
}
var acckapp = await this.restClient.execPost(actionBody, settings.centerAppUrl() + "auth/accessAuth/getVerifyCodeByMoblie");
var result = acckapp.stdout;
if (result) {
var tmp = JSON.parse(result);
return tmp;
if (!actionBody.appInfo) {
return system.getResult(null, "pobj.appInfo can not be empty !");
}
return system.getResult(null, "data is empty");
var acckapp = await this.fetchVCode(actionBody.mobile, actionBody.appInfo.uappKey, actionBody.appInfo.appSecret);
return acckapp;
}
}
......
......@@ -53,118 +53,4 @@ module.exports = function (app) {
res.end(JSON.stringify(r));
});
});
//-----------------------新的模式------------------开始
app.all("/web/*", async function (req, res, next) {
var result = system.getResult(null, "req method must is post");
if (req.method != "POST") {
res.end(JSON.stringify(result));
return;
}
if (!req.body.actionType) {
result.msg = "actionType can not be empty";
res.end(JSON.stringify(result));
return;
}
if (req.body.actionType == "getAppTokenByHosts") {
req.body.actionBody.app_hosts = req.host;
next();
return;
}
var token = req.headers["token"] || "";
if (!token) {
result.msg = "req headers token can not be empty";
res.end(JSON.stringify(result));
return;
}
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppTokenByHostsCache"].getCache(token, system.exTime);
if (result.status != 0) {
res.end(JSON.stringify(result));
return result;
}
req.appInfo = result.data;
req.body.actionProcess = req.appInfo.app_code;
var lst = [
"subTmOrder", "getTmOrderList",
"getTmOrderInfo", "getTmApplyInfo",
"getTmNclList", "getNeedInfo",
"tmConfirm", "updateTmInfo",
"updateNclInfo", "updateContacts",
"updateCustomerInfo", "addOrderAndDelivery",
"updateOrderPayStatus"
];
if (lst.indexOf(req.body.actionType) >= 0) {
var userpin = req.headers["userpin"] || "";
if (!userpin) {
result.msg = "req headers userpin can not be empty";
res.end(JSON.stringify(result));
return;
} else {
var result = await cacheManager["AppUserPinByChannelUserId"].getCache(userpin, system.exTime);
if (result.status != 0) {
res.end(JSON.stringify(result));
return result;
}
req.userInfo = result.data;
}
}//需要用户登录
next();
});
app.get('/web/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"];
var methodName = req.params["method"];
var gname = req.params["gname"];
classPath = gname + "." + classPath;
var tClientIp = system.get_client_ip(req);
req.clientIp = tClientIp;
req.uagent = req.headers["user-agent"];
req.classname = classPath;
var params = [];
params.push(gname);
params.push(methodName);
params.push(req.body);
params.push(req.query);
params.push(req);
var p = null;
var invokeObj = system.getObject("api." + classPath);
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
app.post('/web/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"];
var methodName = req.params["method"];
var gname = req.params["gname"];
var params = [];
classPath = gname + "." + classPath;
var tClientIp = system.get_client_ip(req);
req.clientIp = tClientIp;
req.uagent = req.headers["user-agent"];
req.classname = classPath;
params.push(gname);
params.push(methodName);
params.push(req.body);
params.push(req.query);
params.push(req);
var p = null;
var invokeObj = system.getObject("api." + classPath);
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
//-----------------------新的模式------------------结束
};
......@@ -8,7 +8,7 @@
## **<a name="smsCode"> 短信验证码</a>**
[返回到目录](#menu)
##### URL
[/web/auth/accessAuth/springBoard]
[/auth/accessAuth/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:getVerifyCode
......@@ -33,14 +33,14 @@
## **<a name="pwdLogin"> 密码登录</a>**
[返回到目录](#menu)
##### URL
[/web/auth/accessAuth/springBoard]
[/auth/accessAuth/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:userPinByLgoin
``` javascript
{
"mobile":"15010929366", // Y 手机
"userName":"15010929366", // Y 帐
"password":"123456" // Y 密码
}
```
......@@ -62,7 +62,7 @@
## **<a name="userPinByLgoinVcode"> 验证码登录</a>**
[返回到目录](#menu)
##### URL
[/web/auth/accessAuth/springBoard]
[/auth/accessAuth/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:userPinByLgoinVcode
......@@ -90,7 +90,7 @@
## **<a name="userPinByRegister"> 用户注册</a>**
[返回到目录](#menu)
##### URL
[/web/auth/accessAuth/springBoard]
[/auth/accessAuth/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:userPinByRegister
......
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