@@ -2,6 +2,7 @@ package v2
22
33import (
44 "encoding/base64"
5+ "github.com/1Panel-dev/1Panel/core/utils/common"
56 "os"
67 "path"
78
@@ -29,12 +30,15 @@ func (b *BaseApi) Login(c *gin.Context) {
2930 return
3031 }
3132
32- if ! req .IgnoreCaptcha {
33+ ip := common .GetRealClientIP (c )
34+ needCaptcha := global .IPTracker .NeedCaptcha (ip )
35+ if needCaptcha {
3336 if errMsg := captcha .VerifyCode (req .CaptchaID , req .Captcha ); errMsg != "" {
3437 helper .BadAuth (c , errMsg , nil )
3538 return
3639 }
3740 }
41+
3842 entranceItem := c .Request .Header .Get ("EntranceCode" )
3943 var entrance []byte
4044 if len (entranceItem ) != 0 {
@@ -50,13 +54,18 @@ func (b *BaseApi) Login(c *gin.Context) {
5054 user , msgKey , err := authService .Login (c , req , string (entrance ))
5155 go saveLoginLogs (c , err )
5256 if msgKey == "ErrAuth" || msgKey == "ErrEntrance" {
57+ if msgKey == "ErrAuth" {
58+ global .IPTracker .SetNeedCaptcha (ip )
59+ }
5360 helper .BadAuth (c , msgKey , err )
5461 return
5562 }
5663 if err != nil {
64+ global .IPTracker .SetNeedCaptcha (ip )
5765 helper .InternalServer (c , err )
5866 return
5967 }
68+ global .IPTracker .Clear (ip )
6069 helper .SuccessWithData (c , user )
6170}
6271
@@ -142,15 +151,18 @@ func (b *BaseApi) GetLoginSetting(c *gin.Context) {
142151 helper .InternalServer (c , err )
143152 return
144153 }
154+ ip := common .GetRealClientIP (c )
155+ needCaptcha := global .IPTracker .NeedCaptcha (ip )
145156 res := & dto.LoginSetting {
146- IsDemo : global .CONF .Base .IsDemo ,
147- IsIntl : global .CONF .Base .IsIntl ,
148- IsFxplay : global .CONF .Base .IsFxplay ,
149- IsOffLine : global .CONF .Base .IsOffLine ,
150- Language : settingInfo .Language ,
151- MenuTabs : settingInfo .MenuTabs ,
152- PanelName : settingInfo .PanelName ,
153- Theme : settingInfo .Theme ,
157+ IsDemo : global .CONF .Base .IsDemo ,
158+ IsIntl : global .CONF .Base .IsIntl ,
159+ IsFxplay : global .CONF .Base .IsFxplay ,
160+ IsOffLine : global .CONF .Base .IsOffLine ,
161+ Language : settingInfo .Language ,
162+ MenuTabs : settingInfo .MenuTabs ,
163+ PanelName : settingInfo .PanelName ,
164+ Theme : settingInfo .Theme ,
165+ NeedCaptcha : needCaptcha ,
154166 }
155167 helper .SuccessWithData (c , res )
156168}
0 commit comments