refactor: use EmailExists and add logging

This commit is contained in:
Derrick Hammer 2024-02-13 19:28:23 -05:00
parent 99c440ab88
commit bbb68aecb5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"git.lumeweb.com/LumeWeb/portal/account"
"go.sia.tech/jape"
"go.uber.org/fx"
"go.uber.org/zap"
"net/http"
)
@ -15,16 +16,19 @@ var (
type HttpHandler struct {
accounts *account.AccountServiceDefault
logger *zap.Logger
}
type HttpHandlerParams struct {
fx.In
Accounts *account.AccountServiceDefault
Logger *zap.Logger
}
func NewHttpHandler(params HttpHandlerParams) *HttpHandler {
return &HttpHandler{
accounts: params.Accounts,
logger: params.Logger,
}
}
@ -35,10 +39,13 @@ func (h *HttpHandler) login(jc jape.Context) {
return
}
exists, _ := h.accounts.AccountExistsByEmail(request.Email)
exists, _, err := h.accounts.EmailExists(request.Email)
if !exists {
_ = jc.Error(errInvalidLogin, http.StatusUnauthorized)
if err != nil {
h.logger.Error("failed to check if email exists", zap.Error(err))
}
return
}