Browse Source

fix: 权限校验

hsun 1 year ago
parent
commit
a4a66f1de9
1 changed files with 8 additions and 8 deletions
  1. 8 8
      controllers/base_auth.go

+ 8 - 8
controllers/base_auth.go

@@ -24,7 +24,7 @@ func (this *BaseAuthController) Prepare() {
 		nonce := this.Ctx.Input.Header("nonce")
 		nonce := this.Ctx.Input.Header("nonce")
 		timestamp := this.Ctx.Input.Header("timestamp")
 		timestamp := this.Ctx.Input.Header("timestamp")
 		appid := this.Ctx.Input.Header("appid")
 		appid := this.Ctx.Input.Header("appid")
-		//signature := this.Ctx.Input.Header("signature")
+		signature := this.Ctx.Input.Header("signature")
 
 
 		if nonce == "" {
 		if nonce == "" {
 			errMsg := "随机字符串不能为空"
 			errMsg := "随机字符串不能为空"
@@ -47,13 +47,13 @@ func (this *BaseAuthController) Prepare() {
 			return
 			return
 		}
 		}
 
 
-		//checkSign := utils.GetSign(nonce, timestamp)
-		//if signature != checkSign {
-		//	errMsg := "签名错误"
-		//	this.JSON(models.BaseResponse{Ret: 401, Msg: "", ErrMsg: errMsg}, false, false)
-		//	this.StopRun()
-		//	return
-		//}
+		checkSign := utils.GetSign(nonce, timestamp)
+		if signature != checkSign {
+			errMsg := "签名错误"
+			this.JSON(models.BaseResponse{Ret: 401, Msg: "", ErrMsg: errMsg}, false, false)
+			this.StopRun()
+			return
+		}
 		if method != "GET" && method != "POST" {
 		if method != "GET" && method != "POST" {
 			errMsg := "无效的请求方式"
 			errMsg := "无效的请求方式"
 			this.JSON(models.BaseResponse{Ret: 501, Msg: "", ErrMsg: errMsg}, false, false)
 			this.JSON(models.BaseResponse{Ret: 501, Msg: "", ErrMsg: errMsg}, false, false)