@@ -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
@@ -151,15 +160,18 @@ func (b *BaseApi) GetLoginSetting(c *gin.Context) {
151160 helper .InternalServer (c , err )
152161 return
153162 }
163+ ip := common .GetRealClientIP (c )
164+ needCaptcha := global .IPTracker .NeedCaptcha (ip )
154165 res := & dto.LoginSetting {
155- IsDemo : global .CONF .Base .IsDemo ,
156- IsIntl : global .CONF .Base .IsIntl ,
157- IsFxplay : global .CONF .Base .IsFxplay ,
158- IsOffLine : global .CONF .Base .IsOffLine ,
159- Language : settingInfo .Language ,
160- MenuTabs : settingInfo .MenuTabs ,
161- PanelName : settingInfo .PanelName ,
162- Theme : settingInfo .Theme ,
166+ IsDemo : global .CONF .Base .IsDemo ,
167+ IsIntl : global .CONF .Base .IsIntl ,
168+ IsFxplay : global .CONF .Base .IsFxplay ,
169+ IsOffLine : global .CONF .Base .IsOffLine ,
170+ Language : settingInfo .Language ,
171+ MenuTabs : settingInfo .MenuTabs ,
172+ PanelName : settingInfo .PanelName ,
173+ Theme : settingInfo .Theme ,
174+ NeedCaptcha : needCaptcha ,
163175 }
164176 helper .SuccessWithData (c , res )
165177}
0 commit comments