Commit c62ee2f3 by 蒋勇

Merge branch 'bigdata' of gitlab.gongsibao.com:jiangyong/zhichan into bigdata

parents 8f75b169 b149d5b6
......@@ -10,9 +10,9 @@ 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);
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);
}
......@@ -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,18 +359,18 @@ 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;
async modiPasswordByUserName(pobj, qobj, req) {
var appid = req.app.id;
if (!pobj.userName) {
return system.getResult(null, "账号不能未空.");
}
......@@ -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,9 +410,9 @@ 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
password: pobj.password || pobj.mobile
}
ruser = await this.userSve.register(param);
}
......
......@@ -34,11 +34,24 @@ class CacheBase {
this.redisClient.sadd(this.cacheCacheKeyPrefix, [cachekey + "|" + this.desc]);
return JSON.parse(objvalstr);
} else {
this.redisClient.setWithEx(cachekey, cacheValue, ex);
return JSON.parse(cacheValue);
}
}
async invalidate(inputkey){
const cachekey=this.prefix+inputkey;
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);
return 0;
}
......
......@@ -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");
......
......@@ -3,6 +3,7 @@ const uuidv4 = require('uuid/v4');
class AuthUtils {
constructor() {
this.cacheManager = system.getObject("db.common.cacheManager");
this.exTime = 5 * 3600;//缓存过期时间,5小时
}
getUUID() {
var uuid = uuidv4();
......@@ -16,11 +17,11 @@ class AuthUtils {
*/
async getTokenInfo(appkey, secret) {
var rtnKey = this.getUUID();
var cacheAccessKey = await this.cacheManager["ApiAccessKeyClientCache"].cache(appkey, rtnKey, 3600);
var cacheAccessKey = await this.cacheManager["ApiAccessKeyCache"].cache(appkey, rtnKey, this.exTime);
if (cacheAccessKey) {
rtnKey = cacheAccessKey.accessKey;
}//获取之前的token值
var appData = await this.cacheManager["ApiAccessKeyCache"].cache(rtnKey, secret, 3600, appkey);
var appData = await this.cacheManager["ApiAccessKeyCache"].cache(rtnKey, secret, this.exTime, appkey);
if (!appData) {
return system.getResultFail(system.getAppInfoFail, "key或secret错误.");
}
......
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