chore: extract mail to it's own service

This commit is contained in:
2024-09-27 23:21:37 +02:00
parent a70138f2f7
commit 8e44a3e649
3 changed files with 18 additions and 5 deletions

View File

@@ -76,7 +76,7 @@ func (handler HandlerAuthImpl) handleSignIn() http.HandlerFunc {
http.Error(w, "Invalid email or password", http.StatusUnauthorized) http.Error(w, "Invalid email or password", http.StatusUnauthorized)
} else { } else {
utils.LogError("Error signing in", err) utils.LogError("Error signing in", err)
http.Error(w, "An error occurred", http.StatusInternalServerError) http.Error(w, "InternalServerErr", http.StatusInternalServerError)
} }
return return
} }

11
handler/auth_test.go Normal file
View File

@@ -0,0 +1,11 @@
package handler
import (
"testing"
)
func TestHandleSignIn(t *testing.T) {
t.Parallel()
t.Run("should signIn and return session cookie", func(t *testing.T) {
})
}

View File

@@ -400,7 +400,8 @@ func HandleDeleteAccountComp(db *sql.DB, serverSettings *types.ServerSettings) h
return return
} }
go mailService.SendMail(user.Email, "Account deleted", "Your account has been deleted") //TODO
// go utils.SendMail(user.Email, "Account deleted", "Your account has been deleted")
utils.DoRedirect(w, r, "/") utils.DoRedirect(w, r, "/")
} }
@@ -579,7 +580,8 @@ func HandleResetPasswordComp(db *sql.DB, serverSettings *types.ServerSettings) h
utils.TriggerToast(w, r, "error", "Internal Server Error") utils.TriggerToast(w, r, "error", "Internal Server Error")
return return
} }
mailService.SendMail(email, "Reset Password", mail.String()) //TODO
// utils.SendMail(email, "Reset Password", mail.String())
} }
utils.TriggerToast(w, r, "info", "If the email exists, an email has been sent") utils.TriggerToast(w, r, "info", "If the email exists, an email has been sent")
@@ -615,8 +617,8 @@ func sendVerificationEmail(db *sql.DB, userId string, email string, serverSettin
utils.LogError("Could not render welcome email", err) utils.LogError("Could not render welcome email", err)
return return
} }
mailService := NewMailService(serverSettings) //TODO
mailService.SendMail(email, "Welcome to ME-FIT", w.String()) // utils.SendMail(email, "Welcome to ME-FIT", w.String())
} }
func TryCreateSessionAndSetCookie(r *http.Request, w http.ResponseWriter, db *sql.DB, user_uuid uuid.UUID) error { func TryCreateSessionAndSetCookie(r *http.Request, w http.ResponseWriter, db *sql.DB, user_uuid uuid.UUID) error {