Просмотр исходного кода

fix: User disabled can not work (#133)

---
Closes: #133
lejianwen месяцев назад: 11
Родитель
Сommit
7d6bc2a74f
3 измененных файлов с 21 добавлено и 3 удалено
  1. 8 3
      http/controller/admin/login.go
  2. 5 0
      http/controller/api/login.go
  3. 8 0
      http/middleware/admin.go

+ 8 - 3
http/controller/admin/login.go

@@ -182,15 +182,20 @@ func (ct *Login) Login(c *gin.Context) {
182 182
 		global.Logger.Warn(fmt.Sprintf("Login Fail: %s %s %s", "UsernameOrPasswordError", c.RemoteIP(), clientIp))
183 183
 		loginLimiter.RecordFailure(clientIp)
184 184
 		if loginLimiter.NeedsCaptcha(clientIp) {
185
-			// 移除原验证码,重新生成
186 185
 			loginLimiter.RemoveCaptcha(clientIp)
187
-			response.Fail(c, 110, response.TranslateMsg(c, "UsernameOrPasswordError"))
188
-			return
189 186
 		}
190 187
 		response.Fail(c, 101, response.TranslateMsg(c, "UsernameOrPasswordError"))
191 188
 		return
192 189
 	}
193 190
 
191
+	if !service.AllService.UserService.CheckUserEnable(u) {
192
+		if loginLimiter.NeedsCaptcha(clientIp) {
193
+			loginLimiter.RemoveCaptcha(clientIp)
194
+		}
195
+		response.Fail(c, 101, response.TranslateMsg(c, "UserDisabled"))
196
+		return
197
+	}
198
+
194 199
 	ut := service.AllService.UserService.Login(u, &model.LoginLog{
195 200
 		UserId:   u.Id,
196 201
 		Client:   model.LoginLogClientWebAdmin,

+ 5 - 0
http/controller/api/login.go

@@ -51,6 +51,11 @@ func (l *Login) Login(c *gin.Context) {
51 51
 		return
52 52
 	}
53 53
 
54
+	if !service.AllService.UserService.CheckUserEnable(u) {
55
+		response.Error(c, response.TranslateMsg(c, "UserDisabled"))
56
+		return
57
+	}
58
+
54 59
 	//根据refer判断是webclient还是app
55 60
 	ref := c.GetHeader("referer")
56 61
 	if ref != "" {

+ 8 - 0
http/middleware/admin.go

@@ -24,6 +24,14 @@ func AdminAuth() gin.HandlerFunc {
24 24
 			return
25 25
 		}
26 26
 
27
+		if !service.AllService.UserService.CheckUserEnable(user) {
28
+			c.JSON(401, gin.H{
29
+				"error": "Unauthorized",
30
+			})
31
+			c.Abort()
32
+			return
33
+		}
34
+
27 35
 		c.Set("curUser", user)
28 36
 		c.Set("token", token)
29 37
 		//如果时间小于1天,token自动续期