gorm update

This commit is contained in:
2025-05-07 15:32:05 +08:00
parent 68606c76f9
commit 38ee553cf3
18 changed files with 283 additions and 301 deletions

View File

@@ -167,11 +167,15 @@ func (h *UserHandler) Login(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
switch r.Method {
case http.MethodGet:
if h.Middleware.IsAuth(ctx) && h.Middleware.RefreshToken(ctx) {
http.Redirect(w, r, "/home.html", http.StatusFound)
return
user := h.AuthUser(ctx)
if user.ID > 0 {
if err := h.RenewToken(ctx); err == nil {
http.Redirect(w, r, "/home.html", http.StatusFound)
return
}
}
_ = h.Middleware.Destroy(ctx)
_ = h.Destroy(ctx)
h.HTML(w, r, "oauth/login.tmpl", nil)
case http.MethodPost:
defer func(Body io.ReadCloser) {
@@ -207,7 +211,7 @@ func (h *UserHandler) Login(w http.ResponseWriter, r *http.Request) {
}
func (h *UserHandler) Logout(w http.ResponseWriter, r *http.Request) {
err := h.Middleware.Destroy(r.Context())
err := h.Destroy(r.Context())
if err != nil {
h.Log.Error(err.Error(), err)
}