wip
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 1m8s

This commit is contained in:
2025-12-25 07:36:58 +01:00
parent 1c091dc924
commit aaddb84144
23 changed files with 379 additions and 366 deletions

View File

@@ -5,9 +5,9 @@ import (
"log/slog"
"net/http"
"net/url"
"spend-sparrow/internal/auth_types"
"spend-sparrow/internal/authentication/template"
"spend-sparrow/internal/core"
"spend-sparrow/internal/types"
"spend-sparrow/internal/utils"
"time"
)
@@ -79,7 +79,7 @@ func (handler HandlerImpl) handleSignIn() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
core.UpdateSpan(r)
user, err := utils.WaitMinimumTime(securityWaitDuration, func() (*User, error) {
user, err := utils.WaitMinimumTime(securityWaitDuration, func() (*auth_types.User, error) {
session := core.GetSession(r)
email := r.FormValue("email")
password := r.FormValue("password")
@@ -89,14 +89,14 @@ func (handler HandlerImpl) handleSignIn() http.HandlerFunc {
return nil, err
}
cookie := middleware.CreateSessionCookie(session.Id)
cookie := core.CreateSessionCookie(session.Id)
http.SetCookie(w, &cookie)
return user, nil
})
if err != nil {
if errors.Is(err, service.ErrInvalidCredentials) {
if errors.Is(err, ErrInvalidCredentials) {
utils.TriggerToastWithStatus(r.Context(), w, r, "error", "Invalid email or password", http.StatusUnauthorized)
} else {
utils.TriggerToastWithStatus(r.Context(), w, r, "error", "An error occurred", http.StatusInternalServerError)
@@ -127,7 +127,7 @@ func (handler HandlerImpl) handleSignUpPage() http.HandlerFunc {
return
}
signUpComp := auth.SignInOrUpComp(false)
signUpComp := template.SignInOrUpComp(false)
handler.render.RenderLayout(r, w, signUpComp, nil)
}
}
@@ -147,7 +147,7 @@ func (handler HandlerImpl) handleSignUpVerifyPage() http.HandlerFunc {
return
}
signIn := auth.VerifyComp()
signIn := template.VerifyComp()
handler.render.RenderLayout(r, w, signIn, user)
}
}
@@ -180,7 +180,7 @@ func (handler HandlerImpl) handleSignUpVerifyResponsePage() http.HandlerFunc {
err := handler.service.VerifyUserEmail(r.Context(), token)
isVerified := err == nil
comp := auth.VerifyResponseComp(isVerified)
comp := template.VerifyResponseComp(isVerified)
var status int
if isVerified {
@@ -214,14 +214,14 @@ func (handler HandlerImpl) handleSignUp() http.HandlerFunc {
if err != nil {
switch {
case errors.Is(err, types.ErrInternal):
case errors.Is(err, core.ErrInternal):
utils.TriggerToastWithStatus(r.Context(), w, r, "error", "An error occurred", http.StatusInternalServerError)
return
case errors.Is(err, service.ErrInvalidEmail):
case errors.Is(err, ErrInvalidEmail):
utils.TriggerToastWithStatus(r.Context(), w, r, "error", "The email provided is invalid", http.StatusBadRequest)
return
case errors.Is(err, service.ErrInvalidPassword):
utils.TriggerToastWithStatus(r.Context(), w, r, "error", service.ErrInvalidPassword.Error(), http.StatusBadRequest)
case errors.Is(err, ErrInvalidPassword):
utils.TriggerToastWithStatus(r.Context(), w, r, "error", ErrInvalidPassword.Error(), http.StatusBadRequest)
return
}
// If err is "service.ErrAccountExists", then just continue
@@ -270,7 +270,7 @@ func (handler HandlerImpl) handleDeleteAccountPage() http.HandlerFunc {
return
}
comp := auth.DeleteAccountComp()
comp := template.DeleteAccountComp()
handler.render.RenderLayout(r, w, comp, user)
}
}
@@ -289,7 +289,7 @@ func (handler HandlerImpl) handleDeleteAccountComp() http.HandlerFunc {
err := handler.service.DeleteAccount(r.Context(), user, password)
if err != nil {
if errors.Is(err, service.ErrInvalidCredentials) {
if errors.Is(err, ErrInvalidCredentials) {
utils.TriggerToastWithStatus(r.Context(), w, r, "error", "Password not correct", http.StatusBadRequest)
} else {
utils.TriggerToastWithStatus(r.Context(), w, r, "error", "Internal Server Error", http.StatusInternalServerError)
@@ -314,7 +314,7 @@ func (handler HandlerImpl) handleChangePasswordPage() http.HandlerFunc {
return
}
comp := auth.ChangePasswordComp(isPasswordReset)
comp := template.ChangePasswordComp(isPasswordReset)
handler.render.RenderLayout(r, w, comp, user)
}
}
@@ -353,7 +353,7 @@ func (handler HandlerImpl) handleForgotPasswordPage() http.HandlerFunc {
return
}
comp := auth.ResetPasswordComp()
comp := template.ResetPasswordComp()
handler.render.RenderLayout(r, w, comp, user)
}
}