Commit 2149c0fc by linboxuan

lin add submitService/editService,delete getWay pushlog select

parent d3e0fe5e
var WEBBase = require("../../web.base"); var WEBBase = require("../../web.base");
var system = require("../../../system"); var system = require("../../../system");
class AccessAuthAPI extends WEBBase { class AccessAuthAPI extends WEBBase {
constructor() { constructor() {
super(); super();
this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve"); this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
this.utilsNeedSve = system.getObject("service.utilsSve.utilsNeedSve"); this.utilsNeedSve = system.getObject("service.utilsSve.utilsNeedSve");
this.utilsTmAliyunSve = system.getObject("service.utilsSve.utilsTmAliyunSve");//测试用 this.utilsTmAliyunSve = system.getObject("service.utilsSve.utilsTmAliyunSve");//测试用
}
/**
* 接口跳转-POST请求
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionProcess) {
return system.getResult(null, "actionProcess参数不能为空");
} }
/** if (!pobj.actionType) {
* 接口跳转-POST请求 return system.getResult(null, "actionType参数不能为空");
* action_process 执行的流程 }
* action_type 执行的类型 var result = await this.opActionProcess(pobj, pobj.actionType, req);
* action_body 执行的参数 return result;
*/ }
async springBoard(pobj, qobj, req) { async opActionProcess(pobj, action_type, req) {
if (!pobj.actionProcess) { var opResult = system.getResult(null, "req Failure");
return system.getResult(null, "actionProcess参数不能为空"); pobj.actionBody.userpin = pobj.actionBody.userpin || this.getUUID();
switch (action_type) {
// sy
case "test"://测试
// var rpcParam = {
// accessKeyId: "LTAI4Fgz1uoUpfHpa79iq3XV",
// accessKeySecret: "up8vlX0wzwCVtRAjKRXsCrFta6CHOY",
// endpoint: "https://trademark.aliyuncs.com",
// apiVersion: "2019-09-02"
// };
// opResult = await this.utilsTmAliyunSve.getAliOssInfo(null, "ATTORNEY", rpcParam);
// opResult = system.getResultSuccess(null, "测试成功");
opResult = system.getResultSuccess(null, "测试成功");
break;
case "getTokenInfo"://渠道通过账户进行登录,有则返回用户信息,没有则创建用户
opResult = system.getResultSuccess({
app_code: pobj.appInfo.app_code,
app_hosts: pobj.appInfo.app_hosts,
uapp_id: pobj.appInfo.uapp_id,
uapp_key: pobj.appInfo.uapp_key,
id: pobj.appInfo.id
})
break;
case "getNeedUserPinByChannelUserId"://渠道通过账户进行登录,有则返回用户信息,没有则创建用户
opResult = await this.utilsAuthSve.getLoginByUserName(req, pobj, pobj.actionBody);
if (opResult.status != 0) {
return opResult;
} }
if (!pobj.actionType) { //获取需求信息
return system.getResult(null, "actionType参数不能为空"); pobj.actionType = "getItemByChannelNeedNo";
var needResult = await this.utilsNeedSve.getItemByChannelNeedNo(pobj, pobj.actionBody);
if (needResult.status != 0) {
return needResult;
} }
var result = await this.opActionProcess(pobj, pobj.actionType, req); opResult.data.channelTypeCode = needResult.data.channelTypeCode;
return result; opResult.data.typeCode = needResult.data.typeCode
} break;
async opActionProcess(pobj, action_type, req) { case "getLoginByUserName"://渠道通过账户进行登录,有则返回用户信息,没有则创建用户
var opResult = system.getResult(null, "req Failure"); opResult = await this.utilsAuthSve.getLoginByUserName(req, pobj, pobj.actionBody);
pobj.actionBody.userpin = pobj.actionBody.userpin || this.getUUID(); break;
switch (action_type) { case "getVerifyCode"://获取默认模板的手机验证码---已优化
// sy opResult = await this.utilsAuthSve.getVerifyCodeByMoblie(req, pobj, pobj.actionBody);
case "test"://测试 if (opResult.status == 0) {
// var rpcParam = { return system.getResultSuccess()
// accessKeyId: "LTAI4Fgz1uoUpfHpa79iq3XV", }
// accessKeySecret: "up8vlX0wzwCVtRAjKRXsCrFta6CHOY", break;
// endpoint: "https://trademark.aliyuncs.com", case "userPinByLgoin"://通过账户和密码登录---已优化
// apiVersion: "2019-09-02" opResult = await this.utilsAuthSve.getReqUserPinByLgoin(req, pobj, pobj.actionBody);
// }; if (opResult.status == 0) {
// opResult = await this.utilsTmAliyunSve.getAliOssInfo(null, "ATTORNEY", rpcParam); return opResult;
// opResult = system.getResultSuccess(null, "测试成功");
opResult = system.getResultSuccess(null, "测试成功");
break;
case "getTokenInfo"://渠道通过账户进行登录,有则返回用户信息,没有则创建用户
opResult = system.getResultSuccess({
app_code: pobj.appInfo.app_code,
app_hosts: pobj.appInfo.app_hosts,
uapp_id: pobj.appInfo.uapp_id,
uapp_key: pobj.appInfo.uapp_key,
id: pobj.appInfo.id
})
break;
case "getNeedUserPinByChannelUserId"://渠道通过账户进行登录,有则返回用户信息,没有则创建用户
opResult = await this.utilsAuthSve.getLoginByUserName(req, pobj, pobj.actionBody);
if (opResult.status != 0) {
return opResult;
}
//获取需求信息
pobj.actionType = "getItemByChannelNeedNo";
var needResult = await this.utilsNeedSve.getItemByChannelNeedNo(pobj, pobj.actionBody);
if (needResult.status != 0) {
return needResult;
}
opResult.data.channelTypeCode = needResult.data.channelTypeCode;
opResult.data.typeCode = needResult.data.typeCode
break;
case "getLoginByUserName"://渠道通过账户进行登录,有则返回用户信息,没有则创建用户
opResult = await this.utilsAuthSve.getLoginByUserName(req, pobj, pobj.actionBody);
break;
case "getVerifyCode"://获取默认模板的手机验证码---已优化
opResult = await this.utilsAuthSve.getVerifyCodeByMoblie(req, pobj, pobj.actionBody);
if (opResult.status == 0) {
return system.getResultSuccess()
}
break;
case "userPinByLgoin"://通过账户和密码登录---已优化
opResult = await this.utilsAuthSve.getReqUserPinByLgoin(req, pobj, pobj.actionBody);
if (opResult.status == 0) {
return opResult;
}
break;
case "userTestLogin": // 假登陆
if (pobj.actionBody.userName == 'usertest' && pobj.actionBody.password == 'usertest') {
return system.getResultSuccess({ userpin: 'ac74c45ca8e745d9b66cd3g8a3g2172a' })
} else {
return system.getResultFail(-1, '用户名或密码错误')
}
case "userPinByLgoinVcode"://通过短信登录信息---已优化
pobj.actionBody.reqType = "login";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(req, pobj, pobj.actionBody);
// if (opResult.status == 0) {
// return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
// }
break;
case "userPinByRegister"://通过短信注册信息---已优化
pobj.actionBody.reqType = "reg";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(req, pobj, pobj.actionBody);
// if (opResult.status == 0) {
// return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
// }
break;
case "putUserPwdByMobile"://通过手机验证码修改用户密码---已优化
opResult = await this.utilsAuthSve.putUserPwdByMobile(pobj, pobj.actionBody);
break;
case "putUserMobileByVcode"://通过手机验证码修改手机号,邮箱
opResult = await this.utilsAuthSve.putUserMobileByVcode(pobj, pobj.actionBody);
break;
case "getLoginInfo"://通过userpin获取用户登录信息--已经废弃,在路由中处理了
opResult = await this.utilsAuthSve.getLoginInfo(pobj, pobj.actionBody);
break;
case "channelUserLogin":
opResult = await this.utilsAuthSve.channelUserLogin(pobj, pobj.actionBody, req);
break;
case "logout"://用户退出--已经废弃,前端自己进行移除userpin信息
opResult = await this.utilsAuthSve.userLogout(pobj, pobj.actionBody);
break;
case "getAllChannels"://获取所有渠道(去重appid、app名字)
opResult = await this.utilsAuthSve.getAllChannels(pobj);
break;
case "getAllService"://获取所有渠道(信息更全一些)
opResult = await this.utilsAuthSve.getAllService(pobj);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
} }
return opResult; break;
case "userTestLogin": // 假登陆
if (pobj.actionBody.userName == 'usertest' && pobj.actionBody.password == 'usertest') {
return system.getResultSuccess({ userpin: 'ac74c45ca8e745d9b66cd3g8a3g2172a' })
} else {
return system.getResultFail(-1, '用户名或密码错误')
}
case "userPinByLgoinVcode"://通过短信登录信息---已优化
pobj.actionBody.reqType = "login";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(req, pobj, pobj.actionBody);
// if (opResult.status == 0) {
// return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
// }
break;
case "userPinByRegister"://通过短信注册信息---已优化
pobj.actionBody.reqType = "reg";
opResult = await this.utilsAuthSve.getReqUserPinByLgoinVcode(req, pobj, pobj.actionBody);
// if (opResult.status == 0) {
// return system.getResultSuccess({ userpin: pobj.actionBody.userpin })
// }
break;
case "putUserPwdByMobile"://通过手机验证码修改用户密码---已优化
opResult = await this.utilsAuthSve.putUserPwdByMobile(pobj, pobj.actionBody);
break;
case "putUserMobileByVcode"://通过手机验证码修改手机号,邮箱
opResult = await this.utilsAuthSve.putUserMobileByVcode(pobj, pobj.actionBody);
break;
case "getLoginInfo"://通过userpin获取用户登录信息--已经废弃,在路由中处理了
opResult = await this.utilsAuthSve.getLoginInfo(pobj, pobj.actionBody);
break;
case "channelUserLogin":
opResult = await this.utilsAuthSve.channelUserLogin(pobj, pobj.actionBody, req);
break;
case "logout"://用户退出--已经废弃,前端自己进行移除userpin信息
opResult = await this.utilsAuthSve.userLogout(pobj, pobj.actionBody);
break;
case "getAllChannels"://获取所有渠道(去重appid、app名字)
opResult = await this.utilsAuthSve.getAllChannels(pobj);
break;
case "getAllService"://获取所有渠道(信息更全一些)
opResult = await this.utilsAuthSve.getAllService(pobj);
break;
case "submitService"://创建渠道(app)
opResult = await this.utilsAuthSve.submitService(pobj);
break;
case "editService"://创建渠道(app)
opResult = await this.utilsAuthSve.editService(pobj);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
} }
return opResult;
}
/** /**
* 接口跳转-POST请求 * 接口跳转-POST请求
* action_process 执行的流程 * action_process 执行的流程
*/ */
async getAppTokenByHosts(pobj, qobj, req) { async getAppTokenByHosts(pobj, qobj, req) {
var token = this.getUUID(); var token = this.getUUID();
pobj.actionBody.reqType = "hosts"; pobj.actionBody.reqType = "hosts";
var opResult = await this.utilsAuthSve.getReqTokenByHosts(pobj.actionBody, token); var opResult = await this.utilsAuthSve.getReqTokenByHosts(pobj.actionBody, token);
return opResult; return opResult;
} }
/** /**
* 接口跳转-POST请求 * 接口跳转-POST请求
* action_process 执行的流程 * action_process 执行的流程
*/ */
async getAppTokenByAppKey(pobj, qobj, req) { async getAppTokenByAppKey(pobj, qobj, req) {
var token = this.getUUID(); var token = this.getUUID();
pobj.actionBody.reqType = "appkey"; pobj.actionBody.reqType = "appkey";
var opResult = await this.utilsAuthSve.getReqTokenByHosts(pobj.actionBody, token); var opResult = await this.utilsAuthSve.getReqTokenByHosts(pobj.actionBody, token);
return opResult; return opResult;
} }
} }
module.exports = AccessAuthAPI; module.exports = AccessAuthAPI;
\ No newline at end of file
...@@ -5,313 +5,332 @@ const jwt = require('jsonwebtoken'); ...@@ -5,313 +5,332 @@ const jwt = require('jsonwebtoken');
const { PDICT } = require("../../../../config/businessConfig"); const { PDICT } = require("../../../../config/businessConfig");
//用户权限操作 //用户权限操作
class UtilsAuthService extends AppServiceBase { class UtilsAuthService extends AppServiceBase {
constructor() { constructor() {
super(); super();
this.centerAppUrl = settings.centerAppUrl(); this.centerAppUrl = settings.centerAppUrl();
}
//---------------登录-----------------------------------------------------
/**
* 解密信息
* @param {*} encryptStr 加密字符串
*/
async decryptInfo(encryptStr) {
var result = await this.decryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, encryptStr);
return result;
}
async getReqTokenByHosts(actionBody, req) { //获取token----改成jwt方式--sy-2020-10-21
if (["hosts", "appkey"].indexOf(actionBody.reqType) < 0) {
return system.getResult(null, "actionBody.reqType is error");
}
if (actionBody.reqType == "hosts") {
if (!actionBody.appHosts) {
return system.getResult(null, "actionBody.appHosts can not be empty");
}
}
if (actionBody.reqType == "appkey") {
if (!actionBody.appkey) {
return system.getResult(null, "actionBody.appkey can not be empty");
}
if (!actionBody.secret) {
return system.getResult(null, "actionBody.secret can not be empty");
}
}
var tmpResult = await this.execPostByTimeOut(req, actionBody, settings.centerAppUrl() + "auth/accessAuth/getTokenByHosts");
if (!tmpResult || tmpResult.status != 0) {
return system.getResult(null, "data is empty");
} }
//---------------登录----------------------------------------------------- if (!tmpResult.data || tmpResult.data.status != 0) {
return system.getResult(null, "data is empty!");
}
let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
let bodyInfo = {
env: settings.env,
id: tmpResult.data.data.id,
uapp_id: tmpResult.data.data.uapp_id,
token_secret: encrypt_info
};
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
//生成tokenid
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
expiresIn: 60 * 60 * 4 //单位秒,4小时
/** });
* 解密信息 return system.getResultSuccess({ token: tokenid });
* @param {*} encryptStr 加密字符串 }
*/ /**
async decryptInfo(encryptStr) { * 渠道通过账户进行登录,有则返回用户信息,没有则创建用户
var result = await this.decryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, encryptStr); * @param {*} pobj
return result; * @param {*} actionBody {channelUserId:XX}
} */
async getReqTokenByHosts(actionBody, req) { //获取token----改成jwt方式--sy-2020-10-21 async getLoginByUserName(req, pobj, actionBody) {//渠道通过账户进行登录,有则返回用户信息,没有则创建用户---actionBody.channelUserId
if (["hosts", "appkey"].indexOf(actionBody.reqType) < 0) { if (!actionBody.channelUserId) {
return system.getResult(null, "actionBody.reqType is error"); return system.getResult(null, "actionBody.channelUserId can not be empty");
} }
if (actionBody.reqType == "hosts") { var tmpResult = await this.execPostByTimeOut(req, pobj, settings.centerAppUrl() + "auth/accessAuth/getLoginByUserName");
if (!actionBody.appHosts) { if (!tmpResult || tmpResult.status != 0) {
return system.getResult(null, "actionBody.appHosts can not be empty"); return system.getResult(null, "data is empty");
} }
} if (!tmpResult.data || tmpResult.data.status != 0) {
if (actionBody.reqType == "appkey") { return system.getResult(null, "data is empty!");
if (!actionBody.appkey) { }
return system.getResult(null, "actionBody.appkey can not be empty"); let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
} let bodyInfo = {
if (!actionBody.secret) { env: settings.env,
return system.getResult(null, "actionBody.secret can not be empty"); user_id: tmpResult.data.data.id,
} uapp_id: tmpResult.data.data.uapp_id,
} userpin_secret: encrypt_info
var tmpResult = await this.execPostByTimeOut(req, actionBody, settings.centerAppUrl() + "auth/accessAuth/getTokenByHosts"); };
if (!tmpResult || tmpResult.status != 0) { const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
return system.getResult(null, "data is empty"); //生成tokenid
} const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
if (!tmpResult.data || tmpResult.data.status != 0) { expiresIn: 60 * 60 * 4 //单位秒,4小时
return system.getResult(null, "data is empty!");
}
let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
let bodyInfo = {
env: settings.env,
id: tmpResult.data.data.id,
uapp_id: tmpResult.data.data.uapp_id,
token_secret: encrypt_info
};
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
//生成tokenid
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
expiresIn: 60 * 60 * 4 //单位秒,4小时
}); });
return system.getResultSuccess({ token: tokenid }); return system.getResultSuccess({ userpin: tokenid });
} }
/**
* 渠道通过账户进行登录,有则返回用户信息,没有则创建用户
* @param {*} pobj
* @param {*} actionBody {channelUserId:XX}
*/
async getLoginByUserName(req, pobj, actionBody) {//渠道通过账户进行登录,有则返回用户信息,没有则创建用户---actionBody.channelUserId
if (!actionBody.channelUserId) {
return system.getResult(null, "actionBody.channelUserId can not be empty");
}
var tmpResult = await this.execPostByTimeOut(req, pobj, settings.centerAppUrl() + "auth/accessAuth/getLoginByUserName");
if (!tmpResult || tmpResult.status != 0) {
return system.getResult(null, "data is empty");
}
if (!tmpResult.data || tmpResult.data.status != 0) {
return system.getResult(null, "data is empty!");
}
let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
let bodyInfo = {
env: settings.env,
user_id: tmpResult.data.data.id,
uapp_id: tmpResult.data.data.uapp_id,
userpin_secret: encrypt_info
};
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
//生成tokenid
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
expiresIn: 60 * 60 * 4 //单位秒,4小时
}); /**
return system.getResultSuccess({ userpin: tokenid }); * 通过账户和密码登录
* @param {*} req
* @param {*} pobj
* @param {*} actionBody {userName:XX,password:XXX}
*/
async getReqUserPinByLgoin(req, pobj, actionBody) {
if (!actionBody.userName) {
return system.getResult(null, "用户名不能为空");
} }
if (!actionBody.password) {
return system.getResult(null, "密码不能为空");
}
var tmpResult = await this.execPostByTimeOut(req, pobj, settings.centerAppUrl() + "auth/accessAuth/login");
if (!tmpResult || tmpResult.status != 0) {
return system.getResult(null, "用户名或密码错误");
}
if (!tmpResult.data || tmpResult.data.status != 0) {
return system.getResult(null, "用户名或密码错误!");
}
let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
let bodyInfo = {
env: settings.env,
user_id: tmpResult.data.data.id,
uapp_id: tmpResult.data.data.uapp_id,
userpin_secret: encrypt_info
};
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
//生成tokenid
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
expiresIn: 60 * 60 * 4 //单位秒,4小时
/** });
* 通过账户和密码登录 return system.getResultSuccess({ userpin: tokenid });
* @param {*} req }
* @param {*} pobj /**
* @param {*} actionBody {userName:XX,password:XXX} * 通过短信登录或注册信息
*/ * @param {*} req
async getReqUserPinByLgoin(req, pobj, actionBody) { * @param {*} pobj
if (!actionBody.userName) { * @param {*} actionBody {mobile:XXX,vcode:XXX,reqType:"reg",password:XXX-reqType为reg时有此值}
return system.getResult(null, "用户名不能为空"); */
} async getReqUserPinByLgoinVcode(req, pobj, actionBody) {
if (!actionBody.password) { if (!actionBody.mobile) {
return system.getResult(null, "密码不能为空"); return system.getResult(null, "电话号码不能为空");
} }
var tmpResult = await this.execPostByTimeOut(req, pobj, settings.centerAppUrl() + "auth/accessAuth/login"); if (!actionBody.vcode) {
if (!tmpResult || tmpResult.status != 0) { return system.getResult(null, "验证码不能为空");
return system.getResult(null, "用户名或密码错误"); }
} if (actionBody.reqType == "reg") {
if (!tmpResult.data || tmpResult.data.status != 0) { if (!actionBody.password) {
return system.getResult(null, "用户名或密码错误!"); return system.getResult(null, "actionBody.password can not be empty");
} }
let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data)); }
let bodyInfo = { const tmpResult = await this.execPostByTimeOut(req, pobj, this.centerAppUrl + "auth/accessAuth/loginByVerifyCode", null, null);
env: settings.env, if (!tmpResult || tmpResult.status != 0) {
user_id: tmpResult.data.data.id, return system.getResult(null, tmpResult.msg);
uapp_id: tmpResult.data.data.uapp_id, }
userpin_secret: encrypt_info if (!tmpResult.data || tmpResult.data.status != 0) {
}; return system.getResult(null, tmpResult.data.msg);
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod; }
//生成tokenid let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒 let bodyInfo = {
expiresIn: 60 * 60 * 4 //单位秒,4小时 env: settings.env,
user_id: tmpResult.data.data.id || 0,//新建立的用户时user_id为0
uapp_id: tmpResult.data.data.uapp_id,
userpin_secret: encrypt_info
};
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
//生成tokenid
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
expiresIn: 60 * 60 * 4 //单位秒,4小时
}); });
return system.getResultSuccess({ userpin: tokenid }); return system.getResultSuccess({ userpin: tokenid });
} }
/**
* 通过短信登录或注册信息
* @param {*} req
* @param {*} pobj
* @param {*} actionBody {mobile:XXX,vcode:XXX,reqType:"reg",password:XXX-reqType为reg时有此值}
*/
async getReqUserPinByLgoinVcode(req, pobj, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "电话号码不能为空");
}
if (!actionBody.vcode) {
return system.getResult(null, "验证码不能为空");
}
if (actionBody.reqType == "reg") {
if (!actionBody.password) {
return system.getResult(null, "actionBody.password can not be empty");
}
}
const tmpResult = await this.execPostByTimeOut(req, pobj, this.centerAppUrl + "auth/accessAuth/loginByVerifyCode", null, null);
if (!tmpResult || tmpResult.status != 0) {
return system.getResult(null, tmpResult.msg);
}
if (!tmpResult.data || tmpResult.data.status != 0) {
return system.getResult(null, tmpResult.data.msg);
}
let encrypt_info = await this.encryptStr(PDICT.encrypt_key, PDICT.encrypt_secret, JSON.stringify(tmpResult.data.data));
let bodyInfo = {
env: settings.env,
user_id: tmpResult.data.data.id || 0,//新建立的用户时user_id为0
uapp_id: tmpResult.data.data.uapp_id,
userpin_secret: encrypt_info
};
const tokenSecret = settings.env == "localhost" || settings.env == "dev" ? PDICT.token_secret_dev : PDICT.token_secret_prod;
//生成tokenid
const tokenid = jwt.sign(bodyInfo, tokenSecret, { // expiresIn:过期时间单位是秒
expiresIn: 60 * 60 * 4 //单位秒,4小时
}); /**
return system.getResultSuccess({ userpin: tokenid }); * 获取默认模板的手机验证码
* @param {*} req
* @param {*} pobj
* @param {*} actionBody {mobile:XXX}
*/
async getVerifyCodeByMoblie(req, pobj, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "actionBody.mobile can not be empty !");
} }
const result = await this.execPostByTimeOut(req, pobj, this.centerAppUrl + "auth/accessAuth/getVerifyCodeByMoblie", null, null);
/** if (result.status === 0 && result.data.status != 0) {
* 获取默认模板的手机验证码 return result.data;
* @param {*} req
* @param {*} pobj
* @param {*} actionBody {mobile:XXX}
*/
async getVerifyCodeByMoblie(req, pobj, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "actionBody.mobile can not be empty !");
}
const result = await this.execPostByTimeOut(req, pobj, this.centerAppUrl + "auth/accessAuth/getVerifyCodeByMoblie", null, null);
if (result.status === 0 && result.data.status != 0) {
return result.data;
}
return system.getResultSuccess();
} }
return system.getResultSuccess();
}
/** /**
* 通过手机验证码修改用户密码 * 通过手机验证码修改用户密码
* @param {*} pobj * @param {*} pobj
* @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX} * @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX}
*/ */
async putUserPwdByMobile(pobj, actionBody) { async putUserPwdByMobile(pobj, actionBody) {
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 !");
}
if (!actionBody.vcode) {
return system.getResult(null, "pobj.vcode can not be empty !");
}
if (!actionBody.newPwd) {
return system.getResult(null, "pobj.newPwd 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) {
this.userLogout(pobj, actionBody);
}
return result;
} }
if (!actionBody.vcode) {
/** return system.getResult(null, "pobj.vcode can not be empty !");
* 通过手机验证码修改用户手机号,邮箱
* @param {*} pobj
* @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX}
*/
async putUserMobileByVcode(pobj, actionBody) {
if (!actionBody.vcode) {
return system.getResult(null, "pobj.vcode 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/putUserMobileByVcode");
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");
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 applogout = await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/logout");
return applogout;
} }
if (!actionBody.newPwd) {
/** return system.getResult(null, "pobj.newPwd can not be empty !");
* 解析用户,获取认证token
* @param pobj
* @param actionBody
* @param req
* @returns {Promise<void>}
*/
async channelUserLogin(pobj, actionBody, req) {
let opResult = system.getResultSuccess()
let pin = actionBody.pin;
let result = await this.get360Token();
let token = result.access_token;
//360验证接口
let subData = "pin=" + pin + "&token=" + token;
let url = settings.requestUrl360() + 'api/v1/VerifyPin';
let rtn = await this.restClient.execGet(subData, url);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restGet data is empty");
}
let checkRet = JSON.parse(rtn.stdout);
if (checkRet.code != 200) {
return system.getResultFail(-1, checkRet.msg)
}
//---渠道用户登录,有则返回userpin ,没有则注册用户并返回userpin
actionBody.channelUserId = pin;
opResult = await this.getLoginByUserName(req, pobj, actionBody);
return opResult;
} }
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) {
this.userLogout(pobj, actionBody);
}
return result;
}
async get360Token() { /**
let rtn = await this.execClient.exec360GetToken(settings.tokenUrl360()) * 通过手机验证码修改用户手机号,邮箱
if (!rtn || !rtn.stdout) { * @param {*} pobj
return system.getResult(null, "restPost data is empty"); * @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX}
} */
let result = JSON.parse(rtn.stdout); async putUserMobileByVcode(pobj, actionBody) {
return result; if (!actionBody.vcode) {
return system.getResult(null, "pobj.vcode 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/putUserMobileByVcode");
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");
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 applogout = await this.restPostUrl(pobj, this.centerAppUrl + "auth/accessAuth/logout");
return applogout;
}
/** /**
* 获取所有渠道(去重appid、app名字) * 解析用户,获取认证token
* @returns {Promise<void>} * @param pobj
*/ * @param actionBody
async getAllChannels(pobj) { * @param req
let url = this.centerAppUrl + 'auth/accessAuth/getAllChannels'; * @returns {Promise<void>}
let result = await this.restPostUrl(pobj, url); */
return result async channelUserLogin(pobj, actionBody, req) {
let opResult = system.getResultSuccess()
let pin = actionBody.pin;
let result = await this.get360Token();
let token = result.access_token;
//360验证接口
let subData = "pin=" + pin + "&token=" + token;
let url = settings.requestUrl360() + 'api/v1/VerifyPin';
let rtn = await this.restClient.execGet(subData, url);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restGet data is empty");
}
let checkRet = JSON.parse(rtn.stdout);
if (checkRet.code != 200) {
return system.getResultFail(-1, checkRet.msg)
} }
//---渠道用户登录,有则返回userpin ,没有则注册用户并返回userpin
actionBody.channelUserId = pin;
opResult = await this.getLoginByUserName(req, pobj, actionBody);
return opResult;
}
/** async get360Token() {
* 获取所有渠道(信息更全一些) let rtn = await this.execClient.exec360GetToken(settings.tokenUrl360())
* @returns {Promise<void>} if (!rtn || !rtn.stdout) {
*/ return system.getResult(null, "restPost data is empty");
async getAllService(pobj) {
let url = this.centerAppUrl + 'auth/accessAuth/getAllService';
let result = await this.restPostUrl(pobj, url);
return result
} }
let result = JSON.parse(rtn.stdout);
return result;
}
/**
* 获取所有渠道(去重appid、app名字)
* @returns {Promise<void>}
*/
async getAllChannels(pobj) {
let url = this.centerAppUrl + 'auth/accessAuth/getAllChannels';
let result = await this.restPostUrl(pobj, url);
return result
}
/**
* 获取所有渠道(信息更全一些)
* @returns {Promise<void>}
*/
async getAllService(pobj) {
let url = this.centerAppUrl + 'auth/accessAuth/getAllService';
let result = await this.restPostUrl(pobj, url);
return result
}
/**
* 创建渠道(信息更全一些)
* @returns {Promise<void>}
*/
async submitService(pobj) {
let url = this.centerAppUrl + 'auth/accessAuth/submitService';
let result = await this.restPostUrl(pobj, url);
return result
}
/**
* 修改渠道(信息更全一些)
* @returns {Promise<void>}
*/
async editService(pobj) {
let url = this.centerAppUrl + 'auth/accessAuth/editService';
let result = await this.restPostUrl(pobj, url);
return result
}
} }
module.exports = UtilsAuthService; module.exports = UtilsAuthService;
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