Просмотр исходного кода

feat: Login by pwd can be disable

---

Closes: #141
lejianwen месяцев назад: 11
Родитель
Сommit
6a6a1ed02b

+ 1 - 0
conf/config.yaml

@@ -5,6 +5,7 @@ app:
5 5
   show-swagger: 0 # 1:启用 0:禁用
6 6
   token-expire: 360000
7 7
   web-sso: true #web auth sso
8
+  disable-pwd-login: false #禁用密码登录
8 9
 admin:
9 10
   title: "RustDesk Api Admin"
10 11
   hello-file: "./conf/admin/hello.html"  #优先使用file

+ 6 - 5
config/config.go

@@ -13,11 +13,12 @@ const (
13 13
 )
14 14
 
15 15
 type App struct {
16
-	WebClient   int  `mapstructure:"web-client"`
17
-	Register    bool `mapstructure:"register"`
18
-	ShowSwagger int  `mapstructure:"show-swagger"`
19
-	TokenExpire int  `mapstructure:"token-expire"`
20
-	WebSso      bool `mapstructure:"web-sso"`
16
+	WebClient       int  `mapstructure:"web-client"`
17
+	Register        bool `mapstructure:"register"`
18
+	ShowSwagger     int  `mapstructure:"show-swagger"`
19
+	TokenExpire     int  `mapstructure:"token-expire"`
20
+	WebSso          bool `mapstructure:"web-sso"`
21
+	DisablePwdLogin bool `mapstructure:"disable-pwd-login"`
21 22
 }
22 23
 type Admin struct {
23 24
 	Title     string `mapstructure:"title"`

+ 4 - 0
http/controller/admin/login.go

@@ -152,6 +152,10 @@ var loginLimiter = NewLoginLimiter(3, 5*time.Minute)
152 152
 // @Router /admin/login [post]
153 153
 // @Security token
154 154
 func (ct *Login) Login(c *gin.Context) {
155
+	if global.Config.App.DisablePwdLogin {
156
+		response.Fail(c, 101, response.TranslateMsg(c, "PwdLoginDisabled"))
157
+		return
158
+	}
155 159
 	f := &admin.Login{}
156 160
 	err := c.ShouldBindJSON(f)
157 161
 	clientIp := c.ClientIP()

+ 4 - 0
http/controller/api/login.go

@@ -27,6 +27,10 @@ type Login struct {
27 27
 // @Failure 500 {object} response.ErrorResponse
28 28
 // @Router /login [post]
29 29
 func (l *Login) Login(c *gin.Context) {
30
+	if global.Config.App.DisablePwdLogin {
31
+		response.Error(c, response.TranslateMsg(c, "PwdLoginDisabled"))
32
+		return
33
+	}
30 34
 	f := &api.LoginForm{}
31 35
 	err := c.ShouldBindJSON(f)
32 36
 	//fmt.Println(f)

+ 5 - 0
resources/i18n/en.toml

@@ -133,3 +133,8 @@ other = "Captcha required."
133 133
 description = "Captcha error."
134 134
 one = "Captcha error."
135 135
 other = "Captcha error."
136
+
137
+[PwdLoginDisabled]
138
+description = "Password login disabled."
139
+one = "Password login disabled."
140
+other = "Password login disabled."

+ 6 - 1
resources/i18n/es.toml

@@ -141,4 +141,9 @@ other = "Captcha requerido."
141 141
 [CaptchaError]
142 142
 description = "Captcha error."
143 143
 one = "Error de captcha."
144
-other = "Error de captcha."
144
+other = "Error de captcha."
145
+
146
+[PwdLoginDisabled]
147
+description = "Password login disabled."
148
+one = "Inicio de sesión con contraseña deshabilitado."
149
+other = "Inicio de sesión con contraseña deshabilitado."

+ 5 - 0
resources/i18n/fr.toml

@@ -142,3 +142,8 @@ other = "Captcha requis."
142 142
 description = "Captcha error."
143 143
 one = "Erreur de captcha."
144 144
 other = "Erreur de captcha."
145
+
146
+[PwdLoginDisabled]
147
+description = "Password login disabled."
148
+one = "Connexion par mot de passe désactivée."
149
+other = "Connexion par mot de passe désactivée."

+ 6 - 1
resources/i18n/ko.toml

@@ -135,4 +135,9 @@ other = "Captcha가 필요합니다."
135 135
 [CaptchaError]
136 136
 description = "Captcha error."
137 137
 one = "Captcha 오류."
138
-other = "Captcha 오류."
138
+other = "Captcha 오류."
139
+
140
+[PwdLoginDisabled]
141
+description = "Password login disabled."
142
+one = "비밀번호 로그인이 비활성화되었습니다."
143
+other = "비밀번호 로그인이 비활성화되었습니다."

+ 6 - 1
resources/i18n/ru.toml

@@ -141,4 +141,9 @@ other = "Требуется капча."
141 141
 [CaptchaError]
142 142
 description = "Captcha error."
143 143
 one = "Ошибка капчи."
144
-other = "Ошибка капчи."
144
+other = "Ошибка капчи."
145
+
146
+[PwdLoginDisabled]
147
+description = "Password login disabled."
148
+one = "Вход по паролю отключен."
149
+other = "Вход по паролю отключен."

+ 6 - 1
resources/i18n/zh_CN.toml

@@ -134,4 +134,9 @@ other = "需要验证码。"
134 134
 [CaptchaError]
135 135
 description = "Captcha error."
136 136
 one = "验证码错误。"
137
-other = "验证码错误。"
137
+other = "验证码错误。"
138
+
139
+[PwdLoginDisabled]
140
+description = "Password login disabled."
141
+one = "密码登录已禁用。"
142
+other = "密码登录已禁用。"

+ 6 - 1
resources/i18n/zh_TW.toml

@@ -134,4 +134,9 @@ other = "需要驗證碼。"
134 134
 [CaptchaError]
135 135
 description = "Captcha error."
136 136
 one = "驗證碼錯誤。"
137
-other = "驗證碼錯誤。"
137
+other = "驗證碼錯誤。"
138
+
139
+[PwdLoginDisabled]
140
+description = "Password login disabled."
141
+one = "密碼登錄已禁用。"
142
+other = "密碼登錄已禁用。"