Commit 94f6e74c by 宋毅

tj

parent ea19ea0a
...@@ -4,7 +4,6 @@ class AccessAuthAPI extends APIBase { ...@@ -4,7 +4,6 @@ class AccessAuthAPI extends APIBase {
constructor() { constructor() {
super(); super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils"); this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
} }
/** /**
* 接口跳转-POST请求 * 接口跳转-POST请求
...@@ -40,40 +39,38 @@ class AccessAuthAPI extends APIBase { ...@@ -40,40 +39,38 @@ class AccessAuthAPI extends APIBase {
async opActionProcess(action_process, action_type, action_body, req) { async opActionProcess(action_process, action_type, action_body, req) {
var opResult = system.getResult(null, "req Failure"); var opResult = system.getResult(null, "req Failure");
var userpin = this.getUUID(); var userpin = this.getUUID();
action_body.appInfo = req.appInfo; action_body.appInfo = req.app;
switch (action_type) { switch (action_type) {
// sy // sy
case "test"://测试 case "test"://测试
opResult = system.getResultSuccess(null, "测试成功"); opResult = system.getResultSuccess(null, "测试成功");
break; break;
case "getVerifyCode": case "getVerifyCode":
opResult = await this.opPlatformUtils.getVerifyCodeByMoblie(action_body, action_process, req); opResult = await this.opPlatformUtils.getVerifyCodeByMoblie(action_body);
if (opResult.status == 0) { if (opResult.status == 0) {
return system.getResultSuccess() return system.getResultSuccess()
} }
break; break;
case "loginUserByChannelUserId": case "loginUserByChannelUserId"://????
opResult = await this.utilsAuthSve.loginUserByChannelUserId(action_body, action_process, userpin, req); opResult = await this.opPlatformUtils.loginUserByChannelUserId(action_body, action_process, userpin, req);
if (opResult.status == 0) { if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin }) return system.getResultSuccess({ userpin: userpin })
} }
break; break;
case "userPinByLgoin": 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) { if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin }) return system.getResultSuccess({ userpin: userpin })
} }
break; break;
case "userPinByLgoinVcode": case "userPinByLgoinVcode":
action_body.reqType = "login"; opResult = await this.opPlatformUtils.getReqUserPinByLgoinVcode(action_body, userpin, "login");
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(action_body, action_process, userpin, req);
if (opResult.status == 0) { if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin }) return system.getResultSuccess({ userpin: userpin })
} }
break; break;
case "userPinByRegister": case "userPinByRegister":
action_body.reqType = "reg"; opResult = await this.opPlatformUtils.getReqUserPinByLgoinVcode(action_body, userpin, "reg");
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(action_body, action_process, userpin, req);
if (opResult.status == 0) { if (opResult.status == 0) {
return system.getResultSuccess({ userpin: userpin }) return system.getResultSuccess({ userpin: userpin })
} }
......
...@@ -15,13 +15,22 @@ class AppUserPinByLoginPwdCache extends CacheBase { ...@@ -15,13 +15,22 @@ class AppUserPinByLoginPwdCache extends CacheBase {
return settings.cacheprefix + "_userPin:"; return settings.cacheprefix + "_userPin:";
} }
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var acckapp = await this.restClient.execPost(val, settings.centerAppUrl() + "auth/accessAuth/login"); var actionBody = val;
var result = acckapp.stdout; var uUserName = actionBody.userName;//uUserName
if (result) { var uPassword = actionBody.password;//uPassword
var tmp = JSON.parse(result); var uUserInfo = await this.opPlatformUtils.login(uUserName, uPassword,
return tmp; 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; module.exports = AppUserPinByLoginPwdCache;
...@@ -15,13 +15,36 @@ class AppUserPinByLoginVcodeCache extends CacheBase { ...@@ -15,13 +15,36 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
return settings.cacheprefix + "_userPin:"; return settings.cacheprefix + "_userPin:";
} }
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var acckapp = await this.restClient.execPost(val, settings.centerAppUrl() + "auth/accessAuth/loginByVerifyCode"); var actionBody = val;
var result = acckapp.stdout; var uUserInfo = await this.opPlatformUtils.loginByVCode(actionBody.mobile, actionBody.vcode, actionBody.password,
if (result) { actionBody.appInfo.uapp_key, actionBody.appInfo.uapp_secret);
var tmp = JSON.parse(result); if (uUserInfo.status != 0) {
return tmp; 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; 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 { ...@@ -10,6 +10,7 @@ class OpPlatformUtils {
this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode"; this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode";
this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/loginByMd5Password"; this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/loginByMd5Password";
this.authByCodeUrl = settings.paasUrl() + "api/auth/accessAuth/authByCode"; this.authByCodeUrl = settings.paasUrl() + "api/auth/accessAuth/authByCode";
this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode";
this.exTime = 2 * 3600;//缓存过期时间,2小时 this.exTime = 2 * 3600;//缓存过期时间,2小时
} }
getUUID() { getUUID() {
...@@ -69,8 +70,8 @@ class OpPlatformUtils { ...@@ -69,8 +70,8 @@ class OpPlatformUtils {
} }
return system.getResultSuccess(restResult.data); return system.getResultSuccess(restResult.data);
} }
async fetchVCode(mobile) { async fetchVCode(mobile, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(null, null); var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) { if (reqApiAccessKey.status != 0) {
return reqApiAccessKey; return reqApiAccessKey;
} }
...@@ -151,7 +152,40 @@ class OpPlatformUtils { ...@@ -151,7 +152,40 @@ class OpPlatformUtils {
} }
return system.getResultSuccess(restResult.data); 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) { async getReqTokenByHosts(appHosts, tokenValue) {
if (!appHosts) { if (!appHosts) {
...@@ -203,13 +237,11 @@ class OpPlatformUtils { ...@@ -203,13 +237,11 @@ class OpPlatformUtils {
if (!actionBody.mobile) { if (!actionBody.mobile) {
return system.getResult(null, "pobj.mobile can not be empty !"); return system.getResult(null, "pobj.mobile can not be empty !");
} }
var acckapp = await this.restClient.execPost(actionBody, settings.centerAppUrl() + "auth/accessAuth/getVerifyCodeByMoblie"); if (!actionBody.appInfo) {
var result = acckapp.stdout; return system.getResult(null, "pobj.appInfo can not be empty !");
if (result) {
var tmp = JSON.parse(result);
return tmp;
} }
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) { ...@@ -53,118 +53,4 @@ module.exports = function (app) {
res.end(JSON.stringify(r)); 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 @@ ...@@ -8,7 +8,7 @@
## **<a name="smsCode"> 短信验证码</a>** ## **<a name="smsCode"> 短信验证码</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL ##### URL
[/web/auth/accessAuth/springBoard] [/auth/accessAuth/springBoard]
#### 参数格式 `JSON` #### 参数格式 `JSON`
#### HTTP请求方式 `POST` #### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:getVerifyCode #### 渠道执行的类型 actionType:getVerifyCode
...@@ -33,14 +33,14 @@ ...@@ -33,14 +33,14 @@
## **<a name="pwdLogin"> 密码登录</a>** ## **<a name="pwdLogin"> 密码登录</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL ##### URL
[/web/auth/accessAuth/springBoard] [/auth/accessAuth/springBoard]
#### 参数格式 `JSON` #### 参数格式 `JSON`
#### HTTP请求方式 `POST` #### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:userPinByLgoin #### 渠道执行的类型 actionType:userPinByLgoin
``` javascript ``` javascript
{ {
"mobile":"15010929366", // Y 手机 "userName":"15010929366", // Y 帐
"password":"123456" // Y 密码 "password":"123456" // Y 密码
} }
``` ```
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
## **<a name="userPinByLgoinVcode"> 验证码登录</a>** ## **<a name="userPinByLgoinVcode"> 验证码登录</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL ##### URL
[/web/auth/accessAuth/springBoard] [/auth/accessAuth/springBoard]
#### 参数格式 `JSON` #### 参数格式 `JSON`
#### HTTP请求方式 `POST` #### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:userPinByLgoinVcode #### 渠道执行的类型 actionType:userPinByLgoinVcode
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
## **<a name="userPinByRegister"> 用户注册</a>** ## **<a name="userPinByRegister"> 用户注册</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL ##### URL
[/web/auth/accessAuth/springBoard] [/auth/accessAuth/springBoard]
#### 参数格式 `JSON` #### 参数格式 `JSON`
#### HTTP请求方式 `POST` #### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:userPinByRegister #### 渠道执行的类型 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