优化代码

This commit is contained in:
bjdgyc 2024-10-25 10:41:48 +08:00
parent bd6ee0b140
commit 96fd114c25
1 changed files with 4 additions and 0 deletions

View File

@ -172,6 +172,8 @@ func LinkAuth_otp(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
base.Error(err)
SessStore.DeleteAuthSession(sessionID)
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
@ -181,6 +183,7 @@ func LinkAuth_otp(w http.ResponseWriter, r *http.Request) {
err = xml.Unmarshal(body, &cr) err = xml.Unmarshal(body, &cr)
if err != nil { if err != nil {
base.Error(err) base.Error(err)
SessStore.DeleteAuthSession(sessionID)
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
@ -193,6 +196,7 @@ func LinkAuth_otp(w http.ResponseWriter, r *http.Request) {
// 动态码错误 // 动态码错误
if !dbdata.CheckOtp(username, otp, otpSecret) { if !dbdata.CheckOtp(username, otp, otpSecret) {
if sessionData.AddOtpErrCount(1) > maxOtpErrCount { if sessionData.AddOtpErrCount(1) > maxOtpErrCount {
SessStore.DeleteAuthSession(sessionID)
http.Error(w, "TooManyError, please login again", http.StatusBadRequest) http.Error(w, "TooManyError, please login again", http.StatusBadRequest)
return return
} }