refactor: use EmailExists and add logging
This commit is contained in:
parent
99c440ab88
commit
bbb68aecb5
|
@ -5,6 +5,7 @@ import (
|
||||||
"git.lumeweb.com/LumeWeb/portal/account"
|
"git.lumeweb.com/LumeWeb/portal/account"
|
||||||
"go.sia.tech/jape"
|
"go.sia.tech/jape"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
|
"go.uber.org/zap"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,16 +16,19 @@ var (
|
||||||
|
|
||||||
type HttpHandler struct {
|
type HttpHandler struct {
|
||||||
accounts *account.AccountServiceDefault
|
accounts *account.AccountServiceDefault
|
||||||
|
logger *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpHandlerParams struct {
|
type HttpHandlerParams struct {
|
||||||
fx.In
|
fx.In
|
||||||
Accounts *account.AccountServiceDefault
|
Accounts *account.AccountServiceDefault
|
||||||
|
Logger *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpHandler(params HttpHandlerParams) *HttpHandler {
|
func NewHttpHandler(params HttpHandlerParams) *HttpHandler {
|
||||||
return &HttpHandler{
|
return &HttpHandler{
|
||||||
accounts: params.Accounts,
|
accounts: params.Accounts,
|
||||||
|
logger: params.Logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +39,13 @@ func (h *HttpHandler) login(jc jape.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exists, _ := h.accounts.AccountExistsByEmail(request.Email)
|
exists, _, err := h.accounts.EmailExists(request.Email)
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
_ = jc.Error(errInvalidLogin, http.StatusUnauthorized)
|
_ = jc.Error(errInvalidLogin, http.StatusUnauthorized)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Error("failed to check if email exists", zap.Error(err))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue