Add a login verification code

Fix the site icon
This commit is contained in:
2025-10-24 03:08:43 +08:00
parent abea88da82
commit 7feebbabc0
11 changed files with 348 additions and 106 deletions

View File

@@ -46,6 +46,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
var body struct {
Username string `json:"username"`
Password string `json:"password"`
Captcha string `json:"captcha"`
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
utils.JsonResponse(w, http.StatusBadRequest, false, "请求参数错误", nil)
@@ -55,6 +56,16 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
utils.JsonResponse(w, http.StatusBadRequest, false, "用户名和密码不能为空", nil)
return
}
if body.Captcha == "" {
utils.JsonResponse(w, http.StatusBadRequest, false, "验证码不能为空", nil)
return
}
// 验证验证码
if !VerifyCaptcha(r, body.Captcha) {
utils.JsonResponse(w, http.StatusBadRequest, false, "验证码错误", nil)
return
}
db, err := database.GetDB()
if err != nil {