#73 move workout to new mehtod
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 51s

This commit is contained in:
Tim
2024-08-31 23:31:17 +02:00
parent cda672caac
commit eedaad29fe
6 changed files with 80 additions and 133 deletions

View File

@@ -71,8 +71,8 @@ func HandleSignUp(db *sql.DB) http.HandlerFunc {
user_uuid, err := uuid.NewRandom()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Printf("Could not generate UUID: %v", err)
auth.Error("Internal Server Error").Render(r.Context(), w)
return
}
@@ -84,11 +84,11 @@ func HandleSignUp(db *sql.DB) http.HandlerFunc {
_, err = db.Exec("INSERT INTO user (user_uuid, email, email_verified, is_admin, password, salt, created_at) VALUES (?, ?, FALSE, FALSE, ?, ?, datetime())", user_uuid, email, hash, salt)
if err != nil {
if strings.Contains(err.Error(), "email") {
http.Error(w, "Bad Request", http.StatusBadRequest)
auth.Error("Bad Request").Render(r.Context(), w)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
auth.Error("Internal Server Error").Render(r.Context(), w)
log.Printf("Could not insert user: %v", err)
return
}
@@ -98,7 +98,8 @@ func HandleSignUp(db *sql.DB) http.HandlerFunc {
return
}
http.Redirect(w, r, "/", http.StatusSeeOther)
w.Header().Add("HX-Redirect", "/")
w.WriteHeader(http.StatusOK)
}
}
@@ -142,9 +143,10 @@ func HandleSignIn(db *sql.DB) http.HandlerFunc {
time.Sleep(time.Duration(time_to_wait) * time.Millisecond)
if result {
http.Redirect(w, r, "/", http.StatusSeeOther)
w.Header().Add("HX-Redirect", "/")
w.WriteHeader(http.StatusOK)
} else {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
auth.Error("Invalid email or password").Render(r.Context(), w)
}
}
}
@@ -259,10 +261,9 @@ func verifySessionAndReturnUser(db *sql.DB, r *http.Request) *User {
return nil
}
// TODO: Test
// if created_at.Add(time.Duration(8 * time.Hour)).Before(time.Now()) {
// return nil
// }
if created_at.Add(time.Duration(8 * time.Hour)).Before(time.Now()) {
return nil
}
return &user
}