Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate /user/password to go #555

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions go/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,30 @@ paths:
description: >-
Email verification email sent successfully

/user/password:
post:
summary: >-
Change user password. The user must be authenticated or provide a ticket
tags:
- user
- password
security:
- BearerAuthElevated: []
- {}
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserPasswordRequest'
responses:
'200':
description: >-
Password changed successfully
content:
application/json:
schema:
$ref: '#/components/schemas/OKResponse'

/user/password/reset:
post:
summary: >-
Expand Down Expand Up @@ -432,6 +456,7 @@ components:
- user-not-anonymous
- invalid-pat
- invalid-refresh-token
- invalid-ticket
required:
- status
- message
Expand Down Expand Up @@ -641,6 +666,23 @@ components:
required:
- email

UserPasswordRequest:
type: object
additionalProperties: false
properties:
newPassword:
description: A password of minimum 3 characters
example: Str0ngPassw#ord-94|%
minLength: 3
maxLength: 50
type: string
ticket:
type: string
pattern: ^passwordReset\:.*$
description: Ticket to reset the password, required if the user is not authenticated
required:
- newPassword

OKResponse:
type: string
additionalProperties: false
Expand Down
174 changes: 124 additions & 50 deletions go/api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions go/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions go/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type DBClientGetUser interface {
GetUserByRefreshTokenHash(
ctx context.Context, arg sql.GetUserByRefreshTokenHashParams,
) (sql.AuthUser, error)
GetUserByTicket(ctx context.Context, ticket pgtype.Text) (sql.AuthUser, error)
}

type DBClientInsertUser interface {
Expand All @@ -66,6 +67,9 @@ type DBClientUpdateUser interface {
UpdateUserDeanonymize(ctx context.Context, arg sql.UpdateUserDeanonymizeParams) error
UpdateUserLastSeen(ctx context.Context, id uuid.UUID) (pgtype.Timestamptz, error)
UpdateUserTicket(ctx context.Context, arg sql.UpdateUserTicketParams) (uuid.UUID, error)
UpdateUserChangePassword(
ctx context.Context, arg sql.UpdateUserChangePasswordParams,
) (uuid.UUID, error)
InsertUserWithSecurityKey(
ctx context.Context, arg sql.InsertUserWithSecurityKeyParams,
) (uuid.UUID, error)
Expand Down
14 changes: 13 additions & 1 deletion go/controller/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
ErrUnverifiedUser = &APIError{api.UnverifiedUser}
ErrUserNotAnonymous = &APIError{api.UserNotAnonymous}
ErrInvalidPat = &APIError{api.InvalidPat}
ErrInvalidTicket = &APIError{api.InvalidTicket}
ErrInvalidRequest = &APIError{api.InvalidRequest}
ErrSignupDisabled = &APIError{api.SignupDisabled}
ErrDisabledEndpoint = &APIError{api.DisabledEndpoint}
Expand Down Expand Up @@ -77,6 +78,10 @@ func (response ErrorResponse) VisitPostUserEmailChangeResponse(w http.ResponseWr
return response.visit(w)
}

func (response ErrorResponse) VisitPostUserPasswordResponse(w http.ResponseWriter) error {
return response.visit(w)
}

func (response ErrorResponse) VisitPostUserPasswordResetResponse(w http.ResponseWriter) error {
return response.visit(w)
}
Expand Down Expand Up @@ -119,7 +124,8 @@ func isSensitive(err api.ErrorResponseError) bool {
api.RoleNotAllowed,
api.SignupDisabled,
api.UnverifiedUser,
api.InvalidRefreshToken:
api.InvalidRefreshToken,
api.InvalidTicket:
return true
case
api.DefaultRoleMustBeInAllowedRoles,
Expand Down Expand Up @@ -259,6 +265,12 @@ func (ctrl *Controller) sendError( //nolint:funlen,cyclop
Error: err.t,
Message: "Invalid or expired refresh token",
}
case api.InvalidTicket:
return ErrorResponse{
Status: http.StatusUnauthorized,
Error: err.t,
Message: "Invalid ticket",
}
}

return invalidRequest
Expand Down
Loading