@@ -2,12 +2,14 @@ package v1
22
33import (
44 "encoding/base64"
5+
56 "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
67 "github.com/1Panel-dev/1Panel/backend/app/dto"
78 "github.com/1Panel-dev/1Panel/backend/app/model"
89 "github.com/1Panel-dev/1Panel/backend/constant"
910 "github.com/1Panel-dev/1Panel/backend/global"
1011 "github.com/1Panel-dev/1Panel/backend/utils/captcha"
12+ "github.com/1Panel-dev/1Panel/backend/utils/common"
1113 "github.com/gin-gonic/gin"
1214)
1315
@@ -26,7 +28,9 @@ func (b *BaseApi) Login(c *gin.Context) {
2628 return
2729 }
2830
29- if req .AuthMethod != "jwt" && ! req .IgnoreCaptcha {
31+ ip := common .GetRealClientIP (c )
32+ needCaptcha := global .IPTracker .NeedCaptcha (ip )
33+ if needCaptcha {
3034 if err := captcha .VerifyCode (req .CaptchaID , req .Captcha ); err != nil {
3135 helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
3236 return
@@ -48,9 +52,11 @@ func (b *BaseApi) Login(c *gin.Context) {
4852 user , err := authService .Login (c , req , string (entrance ))
4953 go saveLoginLogs (c , err )
5054 if err != nil {
55+ global .IPTracker .SetNeedCaptcha (ip )
5156 helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
5257 return
5358 }
59+ global .IPTracker .Clear (ip )
5460 helper .SuccessWithData (c , user )
5561}
5662
@@ -134,16 +140,21 @@ func (b *BaseApi) CheckIsIntl(c *gin.Context) {
134140}
135141
136142// @Tags Auth
137- // @Summary Load System Language
138- // @Success 200 {string} language
139- // @Router /auth/language [get]
140- func (b * BaseApi ) GetLanguage (c * gin.Context ) {
143+ // @Summary Load System Setting for login
144+ // @Success 200 {object} dto.LoginSetting
145+ // @Router /auth/setting [get]
146+ func (b * BaseApi ) GetAuthSetting (c * gin.Context ) {
141147 settingInfo , err := settingService .GetSettingInfo ()
142148 if err != nil {
143149 helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
144150 return
145151 }
146- helper .SuccessWithData (c , settingInfo .Language )
152+ ip := common .GetRealClientIP (c )
153+ needCaptcha := global .IPTracker .NeedCaptcha (ip )
154+ helper .SuccessWithData (c , dto.LoginSetting {
155+ NeedCaptcha : needCaptcha ,
156+ Language : settingInfo .Language ,
157+ })
147158}
148159
149160func saveLoginLogs (c * gin.Context , err error ) {
0 commit comments