Skip to content

Commit

Permalink
chore: use existing CheckUnlockPassword function, improve unlock erro…
Browse files Browse the repository at this point in the history
…r message
  • Loading branch information
rolznz committed Feb 1, 2024
1 parent 647e2c7 commit 557e9d2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
)

type HttpService struct {
svc *Service
api *API
encryptionKey string
svc *Service
api *API
}

func NewHttpService(svc *Service) *HttpService {
Expand Down Expand Up @@ -105,8 +104,6 @@ func (httpSvc *HttpService) startHandler(c echo.Context) error {
})
}

httpSvc.encryptionKey = startRequest.UnlockPassword

return c.NoContent(http.StatusNoContent)
}

Expand All @@ -118,8 +115,10 @@ func (httpSvc *HttpService) unlockHandler(c echo.Context) error {
})
}

if unlockRequest.UnlockPassword != httpSvc.encryptionKey {
return c.NoContent(http.StatusUnauthorized)
if !httpSvc.svc.cfg.CheckUnlockPassword(unlockRequest.UnlockPassword) {
return c.JSON(http.StatusUnauthorized, ErrorResponse{
Message: "Invalid password",
})
}

err := httpSvc.saveSessionCookie(c)
Expand Down

0 comments on commit 557e9d2

Please sign in to comment.