fix: restructure env handling for better testing capabillities #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 47s
Build and Push Docker Image / Explore-Gitea-Actions (push) Successful in 55s

This commit was merged in pull request #195.
This commit is contained in:
2024-09-29 23:51:23 +02:00
parent 25e82be339
commit a70138f2f7
15 changed files with 191 additions and 152 deletions

View File

@@ -2,11 +2,12 @@ package handler
import (
"me-fit/service"
"me-fit/types"
"me-fit/utils"
"time"
"database/sql"
"net/http"
"time"
)
type HandlerAuth interface {
@@ -14,33 +15,35 @@ type HandlerAuth interface {
}
type HandlerAuthImpl struct {
db *sql.DB
service service.ServiceAuth
db *sql.DB
service service.ServiceAuth
serverSettings *types.ServerSettings
}
func NewHandlerAuth(db *sql.DB, service service.ServiceAuth) HandlerAuth {
func NewHandlerAuth(db *sql.DB, service service.ServiceAuth, serverSettings *types.ServerSettings) HandlerAuth {
return HandlerAuthImpl{
db: db,
service: service,
db: db,
service: service,
serverSettings: serverSettings,
}
}
func (handler HandlerAuthImpl) handle(router *http.ServeMux) {
// Don't use auth middleware for these routes, as it makes redirecting very difficult, if the mail is not yet verified
router.Handle("/auth/signin", service.HandleSignInPage(handler.db))
router.Handle("/auth/signup", service.HandleSignUpPage(handler.db))
router.Handle("/auth/verify", service.HandleSignUpVerifyPage(handler.db)) // Hint for the user to verify their email
router.Handle("/auth/delete-account", service.HandleDeleteAccountPage(handler.db))
router.Handle("/auth/signin", service.HandleSignInPage(handler.db, handler.serverSettings))
router.Handle("/auth/signup", service.HandleSignUpPage(handler.db, handler.serverSettings))
router.Handle("/auth/verify", service.HandleSignUpVerifyPage(handler.db, handler.serverSettings)) // Hint for the user to verify their email
router.Handle("/auth/delete-account", service.HandleDeleteAccountPage(handler.db, handler.serverSettings))
router.Handle("/auth/verify-email", service.HandleSignUpVerifyResponsePage(handler.db)) // The link contained in the email
router.Handle("/auth/change-password", service.HandleChangePasswordPage(handler.db))
router.Handle("/auth/reset-password", service.HandleResetPasswordPage(handler.db))
router.Handle("/api/auth/signup", service.HandleSignUpComp(handler.db))
router.Handle("/auth/change-password", service.HandleChangePasswordPage(handler.db, handler.serverSettings))
router.Handle("/auth/reset-password", service.HandleResetPasswordPage(handler.db, handler.serverSettings))
router.Handle("/api/auth/signup", service.HandleSignUpComp(handler.db, handler.serverSettings))
router.Handle("/api/auth/signin", handler.handleSignIn())
router.Handle("/api/auth/signout", service.HandleSignOutComp(handler.db))
router.Handle("/api/auth/delete-account", service.HandleDeleteAccountComp(handler.db))
router.Handle("/api/auth/verify-resend", service.HandleVerifyResendComp(handler.db))
router.Handle("/api/auth/delete-account", service.HandleDeleteAccountComp(handler.db, handler.serverSettings))
router.Handle("/api/auth/verify-resend", service.HandleVerifyResendComp(handler.db, handler.serverSettings))
router.Handle("/api/auth/change-password", service.HandleChangePasswordComp(handler.db))
router.Handle("/api/auth/reset-password", service.HandleResetPasswordComp(handler.db))
router.Handle("/api/auth/reset-password", service.HandleResetPasswordComp(handler.db, handler.serverSettings))
router.Handle("/api/auth/reset-password-actual", service.HandleActualResetPasswordComp(handler.db))
}