Skip to content

Commit

Permalink
for reals...
Browse files Browse the repository at this point in the history
  • Loading branch information
bueti committed Nov 13, 2023
1 parent b6036b0 commit 9494743
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ func (app *application) activateUserHandler(c echo.Context) error {
return c.JSON(http.StatusBadRequest, err.Error())
}

user, err := app.models.Tokens.GetUser(model.ScopeActivation, token)
userID, err := app.models.Tokens.GetUserID(model.ScopeActivation, token)
if err != nil {
app.sessionManager.Put(c.Request().Context(), "flash_error", "Invalid token or token expired.")
data := app.newTemplateData(c)
return c.Render(http.StatusBadRequest, "home.tmpl.html", data)
}

err = app.models.Users.Activate(user.ID)
err = app.models.Users.Activate(userID)
if err != nil {
return c.Render(http.StatusInternalServerError, "home.tmpl.html", app.newTemplateData(c))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/model/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ func (m TokenModel) DeleteAllForUser(scope string, userID uuid.UUID) error {
return nil
}

// GetUser returns a user for a given token.
func (m TokenModel) GetUser(scope, token string) (*User, error) {
// GetUserID returns a user for a given token.
func (m TokenModel) GetUserID(scope, token string) (uuid.UUID, error) {
tokenObj := new(Token)
tokenHash := sha256.Sum256([]byte(token))
result := m.DB.Where("scope = ? AND hash = ?", scope, tokenHash[:]).First(&tokenObj)
if result.Error != nil {
return nil, result.Error
return uuid.UUID{}, result.Error
}

return &tokenObj.User, nil
return tokenObj.UserID, nil
}

0 comments on commit 9494743

Please sign in to comment.