feat: Login by pwd can be disable

---

Closes: #141
This commit is contained in:
lejianwen
2025-02-16 13:06:45 +08:00
parent 4b3bbe809d
commit 6a6a1ed02b
11 changed files with 55 additions and 10 deletions
+1
View File
@@ -5,6 +5,7 @@ app:
show-swagger: 0 # 1:启用 0:禁用 show-swagger: 0 # 1:启用 0:禁用
token-expire: 360000 token-expire: 360000
web-sso: true #web auth sso web-sso: true #web auth sso
disable-pwd-login: false #禁用密码登录
admin: admin:
title: "RustDesk Api Admin" title: "RustDesk Api Admin"
hello-file: "./conf/admin/hello.html" #优先使用file hello-file: "./conf/admin/hello.html" #优先使用file
+1
View File
@@ -18,6 +18,7 @@ type App struct {
ShowSwagger int `mapstructure:"show-swagger"` ShowSwagger int `mapstructure:"show-swagger"`
TokenExpire int `mapstructure:"token-expire"` TokenExpire int `mapstructure:"token-expire"`
WebSso bool `mapstructure:"web-sso"` WebSso bool `mapstructure:"web-sso"`
DisablePwdLogin bool `mapstructure:"disable-pwd-login"`
} }
type Admin struct { type Admin struct {
Title string `mapstructure:"title"` Title string `mapstructure:"title"`
+4
View File
@@ -152,6 +152,10 @@ var loginLimiter = NewLoginLimiter(3, 5*time.Minute)
// @Router /admin/login [post] // @Router /admin/login [post]
// @Security token // @Security token
func (ct *Login) Login(c *gin.Context) { func (ct *Login) Login(c *gin.Context) {
if global.Config.App.DisablePwdLogin {
response.Fail(c, 101, response.TranslateMsg(c, "PwdLoginDisabled"))
return
}
f := &admin.Login{} f := &admin.Login{}
err := c.ShouldBindJSON(f) err := c.ShouldBindJSON(f)
clientIp := c.ClientIP() clientIp := c.ClientIP()
+4
View File
@@ -27,6 +27,10 @@ type Login struct {
// @Failure 500 {object} response.ErrorResponse // @Failure 500 {object} response.ErrorResponse
// @Router /login [post] // @Router /login [post]
func (l *Login) Login(c *gin.Context) { func (l *Login) Login(c *gin.Context) {
if global.Config.App.DisablePwdLogin {
response.Error(c, response.TranslateMsg(c, "PwdLoginDisabled"))
return
}
f := &api.LoginForm{} f := &api.LoginForm{}
err := c.ShouldBindJSON(f) err := c.ShouldBindJSON(f)
//fmt.Println(f) //fmt.Println(f)
+5
View File
@@ -133,3 +133,8 @@ other = "Captcha required."
description = "Captcha error." description = "Captcha error."
one = "Captcha error." one = "Captcha error."
other = "Captcha error." other = "Captcha error."
[PwdLoginDisabled]
description = "Password login disabled."
one = "Password login disabled."
other = "Password login disabled."
+5
View File
@@ -142,3 +142,8 @@ other = "Captcha requerido."
description = "Captcha error." description = "Captcha error."
one = "Error de captcha." one = "Error de captcha."
other = "Error de captcha." 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."
+5
View File
@@ -142,3 +142,8 @@ other = "Captcha requis."
description = "Captcha error." description = "Captcha error."
one = "Erreur de captcha." one = "Erreur de captcha."
other = "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."
+5
View File
@@ -136,3 +136,8 @@ other = "Captcha가 필요합니다."
description = "Captcha error." description = "Captcha error."
one = "Captcha 오류." one = "Captcha 오류."
other = "Captcha 오류." other = "Captcha 오류."
[PwdLoginDisabled]
description = "Password login disabled."
one = "비밀번호 로그인이 비활성화되었습니다."
other = "비밀번호 로그인이 비활성화되었습니다."
+5
View File
@@ -142,3 +142,8 @@ other = "Требуется капча."
description = "Captcha error." description = "Captcha error."
one = "Ошибка капчи." one = "Ошибка капчи."
other = "Ошибка капчи." other = "Ошибка капчи."
[PwdLoginDisabled]
description = "Password login disabled."
one = "Вход по паролю отключен."
other = "Вход по паролю отключен."
+5
View File
@@ -135,3 +135,8 @@ other = "需要验证码。"
description = "Captcha error." description = "Captcha error."
one = "验证码错误。" one = "验证码错误。"
other = "验证码错误。" other = "验证码错误。"
[PwdLoginDisabled]
description = "Password login disabled."
one = "密码登录已禁用。"
other = "密码登录已禁用。"
+5
View File
@@ -135,3 +135,8 @@ other = "需要驗證碼。"
description = "Captcha error." description = "Captcha error."
one = "驗證碼錯誤。" one = "驗證碼錯誤。"
other = "驗證碼錯誤。" other = "驗證碼錯誤。"
[PwdLoginDisabled]
description = "Password login disabled."
one = "密碼登錄已禁用。"
other = "密碼登錄已禁用。"