Commit dbd48def by 宋毅

tj

parent 39a1252b
......@@ -29,44 +29,41 @@ class AccessAuthAPI extends APIBase {
case "test"://测试
opResult = system.getResultSuccess(null, "测试成功");
break;
case "getVerifyCode":
case "getVerifyCode"://获取默认模板的手机验证码
opResult = await this.utilsAuthSve.getVerifyCodeByMoblie(pobj, pobj.actionBody);
if (opResult.status == 0) {
return system.getResultSuccess()
}
break;
case "loginUserByChannelUserId":
opResult = await this.utilsAuthSve.loginUserByChannelUserId(pobj, pobj.actionBody);
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
}
break;
case "userPinByLgoin":
case "userPinByLgoin"://通过账户和密码登录
opResult = await this.utilsAuthSve.getReqUserPinByLgoin(pobj, pobj.actionBody);
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
}
break;
case "userPinByLgoinVcode":
case "userPinByLgoinVcode"://通过短信登录信息
pobj.actionBody.reqType = "login";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(pobj, pobj.actionBody);
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
}
break;
case "userPinByRegister":
case "userPinByRegister"://通过短信注册信息
pobj.actionBody.reqType = "reg";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(pobj, pobj.actionBody);
if (opResult.status == 0) {
return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
}
break;
case "logout":
opResult = await this.utilsAuthSve.userLogout(pobj, pobj.actionBody);
break;
case "putUserPwdByMobile":
case "putUserPwdByMobile"://通过手机验证码修改用户密码
opResult = await this.utilsAuthSve.putUserPwdByMobile(pobj, pobj.actionBody);
break;
case "getLoginInfo"://通过userpin获取用户登录信息
opResult = await this.utilsAuthSve.getLoginInfo(pobj, pobj.actionBody);
break;
case "logout"://用户退出
opResult = await this.utilsAuthSve.userLogout(pobj, pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class AppUserPinByChannelUserId extends CacheBase {
constructor() {
super();
this.restClient = system.getObject("util.restClient");
}
desc() {
return "应用中缓存访问token";
}
prefix() {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var acckapp = await this.restClient.execPost(val, settings.centerAppUrl() + "auth/accessAuth/loginUserByChannelUserId");
var result = acckapp.stdout;
if (result) {
var tmp = JSON.parse(result);
return tmp;
}
return system.getResult(null, "data is empty");
}
}
module.exports = AppUserPinByChannelUserId;
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class AppUserPinByLoginPwdCache extends CacheBase {
constructor() {
super();
this.restClient = system.getObject("util.restClient");
}
desc() {
return "应用中缓存访问token";
}
prefix() {
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;
}
return system.getResult(null, "data is empty");
}
}
module.exports = AppUserPinByLoginPwdCache;
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class AppUserPinByLoginVcodeCache extends CacheBase {
constructor() {
super();
this.restClient = system.getObject("util.restClient");
}
desc() {
return "应用中缓存访问token";
}
prefix() {
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;
}
return system.getResult(null, "data is empty");
}
}
module.exports = AppUserPinByLoginVcodeCache;
......@@ -8,26 +8,6 @@ class UtilsAuthSve extends AppServiceBase {
super();
this.centerAppUrl = settings.centerAppUrl();
}
async loginUserByChannelUserId(pobj, actionBody) {
var opResult = null;
switch (pobj.actionProcess) {
case "gsbhome":
opResult = await this.getDefaultUserInfo(pobj, actionBody);
break;
default:
opResult = system.getResult(null, "action_process参数错误");
break;
}
return opResult;
}
async getDefaultUserInfo(pobj, actionBody) {
if (!actionBody.channelUserId) {
return system.getResult(null, "actionBody.channelUserId can not be empty");
}
var result = await this.cacheManager["AppUserPinByChannelUserId"].cache(actionBody.userpin, pobj, system.exTime);
return result;
}
//---------------登录-----------------------------------------------------
async getReqTokenByHosts(actionBody, tokenValue) { //获取token
......@@ -50,7 +30,11 @@ class UtilsAuthSve extends AppServiceBase {
var result = await this.cacheManager["AppTokenByHostsCache"].cache(tokenValue, actionBody, system.exTime);
return result;
}
/**
* 通过账户和密码登录
* @param {*} pobj
* @param {*} actionBody {userName:XX,password:XXX}
*/
async getReqUserPinByLgoin(pobj, actionBody) {
if (!actionBody.userName) {
return system.getResult(null, "actionBody.userName can not be empty");
......@@ -58,9 +42,19 @@ class UtilsAuthSve extends AppServiceBase {
if (!actionBody.password) {
return system.getResult(null, "actionBody.password can not be empty");
}
var result = await this.cacheManager["AppUserPinByLoginPwdCache"].cache(actionBody.userpin, pobj, system.exTime);
return result;
var acckapp = await this.restClient.execPost(pobj, settings.centerAppUrl() + "auth/accessAuth/login");
var result = acckapp.stdout;
if (result) {
var tmp = JSON.parse(result);
return tmp;
}
return system.getResult(null, "data is empty");
}
/**
* 通过短信登录或注册信息
* @param {*} pobj
* @param {*} actionBody {mobile:XXX,vcode:XXX,reqType:"reg",password:XXX-reqType为reg时有此值}
*/
async getReqUserPinByLgoinVcode(pobj, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "actionBody.mobile can not be empty");
......@@ -73,11 +67,20 @@ class UtilsAuthSve extends AppServiceBase {
return system.getResult(null, "actionBody.password can not be empty");
}
}
var result = await this.cacheManager["AppUserPinByLoginVcodeCache"].cache(actionBody.userpin, pobj, system.exTime);
return result;
var acckapp = await this.restClient.execPost(pobj, settings.centerAppUrl() + "auth/accessAuth/loginByVerifyCode");
var result = acckapp.stdout;
if (result) {
var tmp = JSON.parse(result);
return tmp;
}
return system.getResult(null, "data is empty");
}
/**
* 获取默认模板的手机验证码
* @param {*} pobj
* @param {*} actionBody {mobile:XXX}
*/
async getVerifyCodeByMoblie(pobj, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "actionBody.mobile can not be empty !");
......@@ -85,6 +88,11 @@ class UtilsAuthSve extends AppServiceBase {
return await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/getVerifyCodeByMoblie");
}
/**
* 通过手机验证码修改用户密码
* @param {*} pobj
* @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX}
*/
async putUserPwdByMobile(pobj, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "pobj.mobile can not be empty !");
......@@ -95,31 +103,47 @@ class UtilsAuthSve extends AppServiceBase {
if (!actionBody.newPwd) {
return system.getResult(null, "pobj.newPwd can not be empty !");
}
if (!actionBody.userpin) {
return system.getResult(null, "pobj.userpin can not be empty !");
}
if (!pobj.appInfo) {
return system.getResult(null, "pobj.appInfo can not be empty !");
}
var result = await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/modiPasswordByMobile");
if (result.status == 0 && actionBody.userpin) {
if (result.status == 0) {
this.userLogout(pobj, actionBody);
}
return result;
}
/**
* 通过userpin获取用户登录信息
* @param {*} pobj
* @param {*} actionBody {userpin:XXXXX}
*/
async getLoginInfo(pobj, actionBody) {
if (!actionBody.userpin) {
return system.getResult(null, "pobj.userpin can not be empty !");
}
if (!pobj.appInfo) {
return system.getResult(null, "pobj.appInfo can not be empty !");
}
var result = await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/getLoginInfo");
if (result.status == 0) {
this.userLogout(pobj, actionBody);
}
return result;
}
/**
* 用户退出
* @param {*} pobj
* @param {*} actionBody {userpin:XXXX}
*/
async userLogout(pobj, actionBody) {
console.log(actionBody.userpin);
if (!actionBody.userpin) {
return system.getResult(null, "actionBody.userpin can not be empty !");
}
var cacheManager = system.getObject("db.common.cacheManager");
var userinfo = await this.cacheManager["AppUserPinByLoginPwdCache"].cache(actionBody.userpin, pobj, system.exTime);
if(userinfo.data){
pobj.actionBody.userName=userinfo.data.channel_username;
}else{
return system.getResultSuccess();
}
await cacheManager["AppUserPinByLoginVcodeCache"].invalidate(actionBody.userpin);
await cacheManager["AppUserPinByLoginPwdCache"].invalidate(actionBody.userpin);
var applogout=await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/logout");
var applogout = await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/logout");
return applogout;
}
......
var url = require("url");
var system = require("../../base/system");
var utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
module.exports = function (app) {
//-----------------------新的模式------------------开始
......@@ -45,7 +46,7 @@ module.exports = function (app) {
"tmConfirm", "updateTmInfo",
"updateNclInfo", "updateContacts",
"updateCustomerInfo", "addOrderAndDelivery",
"updateOrderPayStatus","getPolicyNeedList","submitPolicyNeedNotes"
"updateOrderPayStatus", "getPolicyNeedList", "submitPolicyNeedNotes"
];
if (lst.indexOf(req.body.actionType) >= 0) {
var userpin = req.headers["userpin"] || "";
......@@ -55,7 +56,13 @@ module.exports = function (app) {
res.end(JSON.stringify(result));
return;
} else {
var result = await cacheManager["AppUserPinByChannelUserId"].getCache(userpin, system.exTime);
var params = {
"actionType": "getLoginInfo",
"actionBody": {
"userpin": userpin
}
}
result = await utilsAuthSve.getLoginInfo(params, params.actionBody);
if (result.status != 0) {
result.status = system.noLogin;
result.msg = "user login is invalidation";
......
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