diff --git a/conf/config.yaml b/conf/config.yaml index c8bc2cc..58a961d 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -5,6 +5,7 @@ app: show-swagger: 0 # 1:启用 0:禁用 token-expire: 360000 web-sso: true #web auth sso + disable-pwd-login: false #禁用密码登录 admin: title: "RustDesk Api Admin" hello-file: "./conf/admin/hello.html" #优先使用file diff --git a/config/config.go b/config/config.go index 08b1734..4a2974c 100644 --- a/config/config.go +++ b/config/config.go @@ -13,11 +13,12 @@ const ( ) type App struct { - WebClient int `mapstructure:"web-client"` - Register bool `mapstructure:"register"` - ShowSwagger int `mapstructure:"show-swagger"` - TokenExpire int `mapstructure:"token-expire"` - WebSso bool `mapstructure:"web-sso"` + WebClient int `mapstructure:"web-client"` + Register bool `mapstructure:"register"` + ShowSwagger int `mapstructure:"show-swagger"` + TokenExpire int `mapstructure:"token-expire"` + WebSso bool `mapstructure:"web-sso"` + DisablePwdLogin bool `mapstructure:"disable-pwd-login"` } type Admin struct { Title string `mapstructure:"title"` diff --git a/http/controller/admin/login.go b/http/controller/admin/login.go index 4a21f1b..68fffef 100644 --- a/http/controller/admin/login.go +++ b/http/controller/admin/login.go @@ -152,6 +152,10 @@ var loginLimiter = NewLoginLimiter(3, 5*time.Minute) // @Router /admin/login [post] // @Security token func (ct *Login) Login(c *gin.Context) { + if global.Config.App.DisablePwdLogin { + response.Fail(c, 101, response.TranslateMsg(c, "PwdLoginDisabled")) + return + } f := &admin.Login{} err := c.ShouldBindJSON(f) clientIp := c.ClientIP() diff --git a/http/controller/api/login.go b/http/controller/api/login.go index f00a44c..adaf89f 100644 --- a/http/controller/api/login.go +++ b/http/controller/api/login.go @@ -27,6 +27,10 @@ type Login struct { // @Failure 500 {object} response.ErrorResponse // @Router /login [post] func (l *Login) Login(c *gin.Context) { + if global.Config.App.DisablePwdLogin { + response.Error(c, response.TranslateMsg(c, "PwdLoginDisabled")) + return + } f := &api.LoginForm{} err := c.ShouldBindJSON(f) //fmt.Println(f) diff --git a/resources/i18n/en.toml b/resources/i18n/en.toml index d6df2e9..bd68267 100644 --- a/resources/i18n/en.toml +++ b/resources/i18n/en.toml @@ -133,3 +133,8 @@ other = "Captcha required." description = "Captcha error." one = "Captcha error." other = "Captcha error." + +[PwdLoginDisabled] +description = "Password login disabled." +one = "Password login disabled." +other = "Password login disabled." \ No newline at end of file diff --git a/resources/i18n/es.toml b/resources/i18n/es.toml index cd63616..f6d1d3d 100644 --- a/resources/i18n/es.toml +++ b/resources/i18n/es.toml @@ -141,4 +141,9 @@ other = "Captcha requerido." [CaptchaError] description = "Captcha error." one = "Error de captcha." -other = "Error de captcha." \ No newline at end of file +other = "Error de captcha." + +[PwdLoginDisabled] +description = "Password login disabled." +one = "Inicio de sesión con contraseña deshabilitado." +other = "Inicio de sesión con contraseña deshabilitado." \ No newline at end of file diff --git a/resources/i18n/fr.toml b/resources/i18n/fr.toml index 6dfdf00..779eae7 100644 --- a/resources/i18n/fr.toml +++ b/resources/i18n/fr.toml @@ -142,3 +142,8 @@ other = "Captcha requis." description = "Captcha error." one = "Erreur de captcha." other = "Erreur de captcha." + +[PwdLoginDisabled] +description = "Password login disabled." +one = "Connexion par mot de passe désactivée." +other = "Connexion par mot de passe désactivée." \ No newline at end of file diff --git a/resources/i18n/ko.toml b/resources/i18n/ko.toml index b6eded0..ee1b07a 100644 --- a/resources/i18n/ko.toml +++ b/resources/i18n/ko.toml @@ -135,4 +135,9 @@ other = "Captcha가 필요합니다." [CaptchaError] description = "Captcha error." one = "Captcha 오류." -other = "Captcha 오류." \ No newline at end of file +other = "Captcha 오류." + +[PwdLoginDisabled] +description = "Password login disabled." +one = "비밀번호 로그인이 비활성화되었습니다." +other = "비밀번호 로그인이 비활성화되었습니다." diff --git a/resources/i18n/ru.toml b/resources/i18n/ru.toml index 9f62376..fc7c12e 100644 --- a/resources/i18n/ru.toml +++ b/resources/i18n/ru.toml @@ -141,4 +141,9 @@ other = "Требуется капча." [CaptchaError] description = "Captcha error." one = "Ошибка капчи." -other = "Ошибка капчи." \ No newline at end of file +other = "Ошибка капчи." + +[PwdLoginDisabled] +description = "Password login disabled." +one = "Вход по паролю отключен." +other = "Вход по паролю отключен." \ No newline at end of file diff --git a/resources/i18n/zh_CN.toml b/resources/i18n/zh_CN.toml index 4e31656..c37b0c5 100644 --- a/resources/i18n/zh_CN.toml +++ b/resources/i18n/zh_CN.toml @@ -134,4 +134,9 @@ other = "需要验证码。" [CaptchaError] description = "Captcha error." one = "验证码错误。" -other = "验证码错误。" \ No newline at end of file +other = "验证码错误。" + +[PwdLoginDisabled] +description = "Password login disabled." +one = "密码登录已禁用。" +other = "密码登录已禁用。" \ No newline at end of file diff --git a/resources/i18n/zh_TW.toml b/resources/i18n/zh_TW.toml index 4388bd3..5490f78 100644 --- a/resources/i18n/zh_TW.toml +++ b/resources/i18n/zh_TW.toml @@ -134,4 +134,9 @@ other = "需要驗證碼。" [CaptchaError] description = "Captcha error." one = "驗證碼錯誤。" -other = "驗證碼錯誤。" \ No newline at end of file +other = "驗證碼錯誤。" + +[PwdLoginDisabled] +description = "Password login disabled." +one = "密碼登錄已禁用。" +other = "密碼登錄已禁用。"