3535 </el-input >
3636 </el-form-item >
3737 </div >
38- <div class =" mb-24" v-if =" loginMode !== 'LDAP' && showCaptcha " >
38+ <div class =" mb-24" v-if =" loginMode !== 'LDAP' && identifyCode " >
3939 <el-form-item prop =" captcha" >
4040 <div class =" flex-between w-full" >
4141 <el-input
@@ -208,73 +208,18 @@ const loginHandle = () => {
208208 .then (() => {
209209 locale .value = localStorage .getItem (' MaxKB-locale' ) || getBrowserLang () || ' en-US'
210210 localStorage .setItem (' workspace_id' , ' default' )
211- localStorage .removeItem (loginForm .value .username )
212211 router .push ({name: ' home' })
213212 })
214213 .catch (() => {
215214 const username = loginForm .value .username
216- localStorage .setItem (username , String (Number (localStorage .getItem (username ) || ' 0' ) + 1 ))
217215 loading .value = false
218- loginForm .value .username = ' '
219- loginForm .value .password = ' '
220- loginForm .value .captcha = ' '
221- const timestampKey = ` ${username }_first_fail_timestamp `
222- if (! localStorage .getItem (timestampKey )) {
223- localStorage .setItem (timestampKey , Date .now ().toString ())
224- }
216+ makeCode (username )
225217 })
226218 }
227219 }
228220 })
229221}
230222
231- const showCaptcha = computed <boolean >(() => {
232- if (! authSetting .value ) return true
233-
234- const maxAttempts = authSetting .value .max_attempts
235-
236- // -1 表示一直不显示
237- if (maxAttempts === - 1 ) {
238- return false
239- }
240-
241- // 0 表示一直显示
242- if (maxAttempts === 0 ) {
243- return true
244- }
245-
246- // 大于 0,根据登录失败次数决定
247- const username = loginForm .value .username ?.trim ()
248- if (! username ) {
249- return false // 没有输入用户名时不显示
250- }
251-
252- const timestampKey = ` ${username }_first_fail_timestamp `
253- const firstFailTimestamp = localStorage .getItem (timestampKey )
254-
255- if (firstFailTimestamp ) {
256- const expirationTime = 10 * 60 * 1000 // 10分钟毫秒数
257- if (Date .now () - parseInt (firstFailTimestamp ) > expirationTime ) {
258- // 过期则清除记录
259- localStorage .removeItem (username )
260- localStorage .removeItem (timestampKey )
261- return false
262- }
263- } else {
264- // 如果没有时间戳但有失败次数,可能是旧数据,清除失败次数
265- const failCount = Number (localStorage .getItem (username ) || ' 0' )
266- if (failCount > 0 ) {
267- localStorage .removeItem (username )
268- return false
269- }
270- }
271-
272- const failCount = Number (localStorage .getItem (username ) || ' 0' )
273- console .log (' failCount' , failCount )
274-
275- return failCount >= maxAttempts
276- })
277-
278223function makeCode(username ? : string ) {
279224 loginApi .getCaptcha (username ).then ((res : any ) => {
280225 if (res && res .data && res .data .captcha ) {
@@ -286,9 +231,7 @@ function makeCode(username?: string) {
286231}
287232
288233function handleUsernameBlur(username : string ) {
289- if (showCaptcha .value ) {
290- makeCode (username )
291- }
234+ makeCode (username )
292235}
293236
294237onBeforeMount (() => {
0 commit comments