feat(auth): #154 send verification mails
This commit was merged in pull request #155.
This commit is contained in:
41
handler.go
41
handler.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"me-fit/middleware"
|
||||
"me-fit/service"
|
||||
"me-fit/template/mail"
|
||||
"me-fit/utils"
|
||||
|
||||
"database/sql"
|
||||
@@ -14,23 +15,37 @@ func getHandler(db *sql.DB) http.Handler {
|
||||
|
||||
router.HandleFunc("/", service.HandleIndexAnd404(db))
|
||||
|
||||
router.HandleFunc("/mail", func(w http.ResponseWriter, r *http.Request) {
|
||||
utils.SendWelcomeMail("timwundenberg@outlook.de")
|
||||
})
|
||||
|
||||
// Serve static files (CSS, JS and images)
|
||||
router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
|
||||
|
||||
router.HandleFunc("/workout", service.HandleWorkoutPage(db))
|
||||
router.HandleFunc("POST /api/workout", service.HandleWorkoutNewComp(db))
|
||||
router.HandleFunc("GET /api/workout", service.HandleWorkoutGetComp(db))
|
||||
router.HandleFunc("DELETE /api/workout/{id}", service.HandleWorkoutDeleteComp(db))
|
||||
router.Handle("/workout", auth(db, service.HandleWorkoutPage(db)))
|
||||
router.Handle("POST /api/workout", auth(db, service.HandleWorkoutNewComp(db)))
|
||||
router.Handle("GET /api/workout", auth(db, service.HandleWorkoutGetComp(db)))
|
||||
router.Handle("DELETE /api/workout/{id}", auth(db, service.HandleWorkoutDeleteComp(db)))
|
||||
|
||||
router.HandleFunc("/auth/signin", service.HandleSignInPage(db))
|
||||
router.HandleFunc("/auth/signup", service.HandleSignUpPage(db))
|
||||
router.HandleFunc("/api/auth/signup", service.HandleSignUpComp(db))
|
||||
router.HandleFunc("/api/auth/signin", service.HandleSignInComp(db))
|
||||
router.HandleFunc("/api/auth/signout", service.HandleSignOutComp(db))
|
||||
// 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(db))
|
||||
router.Handle("/auth/signup", service.HandleSignUpPage(db))
|
||||
router.Handle("/auth/verify", service.HandleSignUpVerifyPage(db)) // Hint for the user to verify their email
|
||||
router.Handle("/auth/verify-email", service.HandleSignUpVerifyResponsePage(db)) // The link contained in the email
|
||||
router.Handle("/api/auth/signup", service.HandleSignUpComp(db))
|
||||
router.Handle("/api/auth/signin", service.HandleSignInComp(db))
|
||||
router.Handle("/api/auth/signout", service.HandleSignOutComp(db))
|
||||
router.Handle("/api/auth/verify-resend", service.HandleVerifyResendComp(db))
|
||||
|
||||
if utils.Environment == "dev" {
|
||||
router.HandleFunc("/mail/", handleMails)
|
||||
}
|
||||
|
||||
return middleware.Logging(middleware.EnableCors(router))
|
||||
}
|
||||
|
||||
func handleMails(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/mail/register" {
|
||||
mail.Register("test-code").Render(r.Context(), w)
|
||||
}
|
||||
}
|
||||
|
||||
func auth(db *sql.DB, h http.Handler) http.Handler {
|
||||
return middleware.EnsureValidSession(db, h)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user