Commit ff45071c by 宋毅

tj

parent 0af66d74
......@@ -10,10 +10,10 @@ class AccessAuthAPI extends APIBase {
this.userSve = system.getObject("service.auth.userSve");
}
/*查询注册用户的信息sys*/
async queryRegUser(pobj, query, req){
var appid=req.app.id;
var userList= await this.userSve.queryUsersByAppId(appid);
return system.getResult(userList);
async queryRegUser(pobj, query, req) {
var appid = req.app.id;
var userList = await this.userSve.queryUsersByAppId(appid);
return system.getResult(userList);
}
/**
* 发送短信
......@@ -43,6 +43,10 @@ class AccessAuthAPI extends APIBase {
if (tmplCode && tmplCode.indexOf("SMS_") < 0) {
return system.getResult(null, "模版编码有误");
}
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile);
if (tmpReslut) {
return system.getResult(system.redoFail, "操作过于频繁,请勿重复获取");
}
var vcodeResult = await this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, tmplCode, 120, signName);
return system.getResult(vcodeResult);
}
......@@ -58,7 +62,11 @@ class AccessAuthAPI extends APIBase {
if (!mobile) {
return system.getResult(null, "电话号码不能为空.");
}
var vcodeResult = this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, null, 60);
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile);
if (tmpReslut) {
return system.getResult(system.redoFail, "操作过于频繁,请勿重复获取");
}
var vcodeResult = this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, null, 120);
return system.getResult(vcodeResult);
}
async authAccessKey(pobj, query, req) {
......@@ -178,7 +186,7 @@ class AccessAuthAPI extends APIBase {
}
var ruser = await this.userSve.getUserByUserMobile(param);
if (!ruser) {
return system.getResult(null,"查无此用户");
return system.getResult(null, "查无此用户");
}
var opencode = super.getUUID();
var authUrl = req.app.authUrl + "?opencode=" + opencode;
......@@ -187,8 +195,8 @@ class AccessAuthAPI extends APIBase {
}
//根据openid查询是否与用户绑定
async checkWxBind(p,q,req){
var openid=p.openid;
async checkWxBind(p, q, req) {
var openid = p.openid;
if (!openid) {
return system.getResult(null, "openid不能为空");
}
......@@ -197,14 +205,14 @@ class AccessAuthAPI extends APIBase {
openid: openid,
}
var ruser = await this.userSve.checkWxBind(param);
if(!ruser){
if (!ruser) {
return system.getResult(null, "用户未绑定微信");
}
return system.getResult(ruser);
}
//根据openid登录
async loginByOpenId(p,q,req){
var openid=p.openid;
async loginByOpenId(p, q, req) {
var openid = p.openid;
if (!openid) {
return system.getResult(null, "openid不能为空");
}
......@@ -213,7 +221,7 @@ class AccessAuthAPI extends APIBase {
openid: openid,
}
var ruser = await this.userSve.checkWxBind(param);
if(!ruser){
if (!ruser) {
return system.getResult(null, "用户未绑定微信");
}
var opencode = super.getUUID();
......@@ -234,23 +242,23 @@ class AccessAuthAPI extends APIBase {
return system.getResult(null, "openid不能未空.");
}
var cacheCode = await this.cacheManager["VCodeCache"].cache(appkey + "_" + pobj.mobile, null);
if (pobj.vcode != cacheCode.vcode) {
if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResult(system.verifyVCodeFail, "验证码校验不成功,请重新获取验证码验证.");
}
var param = {
app_id: req.app.id,
mobile: pobj.mobile,
openid:pobj.openid
openid: pobj.openid
}
var ruser = await this.userSve.wxBind(param);
if (!ruser) {
param = {
app_id: req.app.id,
userName: pobj.mobile,
nickName:pobj.mobile,
nickName: pobj.mobile,
mobile: pobj.mobile,
password: pobj.mobile,
wxopenid:pobj.openid
wxopenid: pobj.openid
}
ruser = await this.userSve.register(param);
}
......@@ -259,8 +267,8 @@ class AccessAuthAPI extends APIBase {
await this.cacheManager["OpenCodeCache"].cache(opencode, ruser, 120);
return system.getResultSuccess({ auth_url: authUrl, opencode: opencode });
}
//wxbind
async wxBindWithoutVCode(pobj, qobj, req) {
//wxbind
async wxBindWithoutVCode(pobj, qobj, req) {
var appkey = req.app.appkey;
if (!pobj.mobile) {
return system.getResult(null, "电话号码不能未空.");
......@@ -272,17 +280,17 @@ class AccessAuthAPI extends APIBase {
var param = {
app_id: req.app.id,
mobile: pobj.mobile,
openid:pobj.openid
openid: pobj.openid
}
var ruser = await this.userSve.wxBind(param);
if (!ruser) {
param = {
app_id: req.app.id,
userName: pobj.mobile,
nickName:pobj.mobile,
nickName: pobj.mobile,
mobile: pobj.mobile,
password: pobj.mobile,
wxopenid:pobj.openid
wxopenid: pobj.openid
}
ruser = await this.userSve.register(param);
}
......@@ -305,7 +313,7 @@ class AccessAuthAPI extends APIBase {
param = {
app_id: req.app.id,
userName: pobj.mobile,
nickName:pobj.mobile,
nickName: pobj.mobile,
mobile: pobj.mobile,
password: pobj.mobile
}
......@@ -338,9 +346,9 @@ class AccessAuthAPI extends APIBase {
/**
* 按照手机号和验证码修改密码
*/
async modiPasswordByMobile(pobj, qobj, req){
var appid=req.app.id;
var appkey=req.app.appkey;
async modiPasswordByMobile(pobj, qobj, req) {
var appid = req.app.id;
var appkey = req.app.appkey;
if (!pobj.mobile) {
return system.getResult(null, "电话号码不能未空.");
}
......@@ -351,19 +359,19 @@ class AccessAuthAPI extends APIBase {
return system.getResult(null, "新密码不能未空.");
}
var cacheCode = await this.cacheManager["VCodeCache"].cache(appkey + "_" + pobj.mobile, null);
if (pobj.vcode != cacheCode.vcode) {
return system.getResultFail(-1, "验证码校验不成功,请重新获取验证码验证.",system.verifyVCodeFail);
if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResultFail(-1, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail);
}
//按照appid和电话查询出要修改的用户
var ruser = await this.userSve.modiPasswordByMobile(appid,pobj.mobile,pobj.newPwd);
var ruser = await this.userSve.modiPasswordByMobile(appid, pobj.mobile, pobj.newPwd);
return system.getResult(ruser);
}
}
/**
* 按照账号和appid修改密码
*/
async modiPasswordByUserName(pobj, qobj, req){
var appid=req.app.id;
if (!pobj.userName) {
async modiPasswordByUserName(pobj, qobj, req) {
var appid = req.app.id;
if (!pobj.userName) {
return system.getResult(null, "账号不能未空.");
}
if (!pobj.newPwd) {
......@@ -372,7 +380,7 @@ class AccessAuthAPI extends APIBase {
// if (!pobj.oldPwd) {
// return system.getResult(null, "旧密码不能未空.");
// }
var ruser = await this.userSve.modiPasswordByUserName(appid,pobj.userName,pobj.newPwd,pobj.oldPwd);
var ruser = await this.userSve.modiPasswordByUserName(appid, pobj.userName, pobj.newPwd, pobj.oldPwd);
return system.getResult(ruser);
}
/**
......@@ -390,7 +398,7 @@ class AccessAuthAPI extends APIBase {
return system.getResult(null, "验证码不能未空.");
}
var cacheCode = await this.cacheManager["VCodeCache"].cache(appkey + "_" + pobj.mobile, null);
if (pobj.vcode != cacheCode.vcode) {
if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResult(system.verifyVCodeFail, "验证码校验不成功,请重新获取验证码验证.");
}
var param = {
......@@ -402,7 +410,7 @@ class AccessAuthAPI extends APIBase {
param = {
app_id: req.app.id,
userName: pobj.mobile,
nickName:pobj.mobile,
nickName: pobj.mobile,
mobile: pobj.mobile,
password: pobj.mobile
}
......@@ -716,7 +724,7 @@ class AccessAuthAPI extends APIBase {
methodName: "queryRegUser",
paramdescs: [
{
}
],
rtnTypeDesc: "返回应用的注册用户",
......
......@@ -38,6 +38,18 @@ class CacheBase {
return JSON.parse(cacheValue);
}
}
async getCache(inputkey, ex) {
const cachekey = this.prefix + inputkey;
var cacheValue = await this.redisClient.get(cachekey);
if (!cacheValue || cacheValue == "undefined" || cacheValue == "null") {
return null;
} else {
if (ex) {
this.redisClient.set(cachekey, cacheValue, ex);
}
return JSON.parse(cacheValue);
}
}
async invalidate(inputkey) {
const cachekey = this.prefix + inputkey;
this.redisClient.delete(cachekey);
......
......@@ -174,6 +174,9 @@ System.userNameLoginFail = 2020;
System.verifyVCodeFail = 2030;
//opencode存储的值已经失效
System.verifyOpencodeFail = 2040;
//重复操作
System.redoFail = 2050;
module.exports = System;
// rc=System.getObject("tool.restClient");
......
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