Skip to content

Commit 0320fee

Browse files
authored
Merge pull request #5 from Nuxify/feature/remove-current-user-field
fix(user): remove current user field in update user password endpoint…
2 parents 228e96a + 7f885b3 commit 0320fee

File tree

8 files changed

+12
-66
lines changed

8 files changed

+12
-66
lines changed

docs/openapi.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,10 @@
496496
}
497497
},
498498
"UpdateUserPasswordRequest": {
499-
"required": ["currentPassword", "newPassword"],
499+
"required": ["password"],
500500
"type": "object",
501501
"properties": {
502-
"currentPassword": {
503-
"type": "string"
504-
},
505-
"newPassword": {
502+
"password": {
506503
"type": "string"
507504
}
508505
}

interfaces/servicecontainer.go

-7
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,10 @@ func (k *kernel) userCommandServiceContainer() *userService.UserCommandService {
9494
MySQLDBHandlerInterface: mysqlDBHandler,
9595
}
9696

97-
queryRepository := &userRepository.UserQueryRepository{
98-
MySQLDBHandlerInterface: mysqlDBHandler,
99-
}
100-
10197
service := &userService.UserCommandService{
10298
UserCommandRepositoryInterface: &userRepository.UserCommandRepositoryCircuitBreaker{
10399
UserCommandRepositoryInterface: repository,
104100
},
105-
UserQueryRepositoryInterface: &userRepository.UserQueryRepositoryCircuitBreaker{
106-
UserQueryRepositoryInterface: queryRepository,
107-
},
108101
}
109102

110103
return service

module/user/infrastructure/repository/UserCommandRepository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (repository *UserCommandRepository) UpdateUserEmailVerifiedAt(email string)
8484
func (repository *UserCommandRepository) UpdateUserPassword(data repositoryTypes.UpdateUserPassword) error {
8585
user := &entity.User{
8686
WalletAddress: data.WalletAddress,
87-
Password: data.NewPassword,
87+
Password: data.Password,
8888
}
8989

9090
// update users

module/user/infrastructure/repository/types/dto.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type UpdateUser struct {
1515
}
1616

1717
type UpdateUserPassword struct {
18-
WalletAddress string
19-
CurrentPassword string
20-
NewPassword string
18+
WalletAddress string
19+
Password string
2120
}

module/user/infrastructure/service/UserCommandService.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/ecdsa"
66
"encoding/base64"
7-
"errors"
87
"fmt"
98
"log"
109

@@ -13,7 +12,6 @@ import (
1312
"github.com/hashicorp/vault/shamir"
1413
"github.com/segmentio/ksuid"
1514

16-
apiError "celeste/internal/errors"
1715
"celeste/internal/password"
1816
"celeste/module/user/domain/repository"
1917
repositoryTypes "celeste/module/user/infrastructure/repository/types"
@@ -23,7 +21,6 @@ import (
2321
// UserCommandService handles the user command service logic
2422
type UserCommandService struct {
2523
repository.UserCommandRepositoryInterface
26-
repository.UserQueryRepositoryInterface
2724
}
2825

2926
// CreateUser create a user
@@ -139,25 +136,14 @@ func (service *UserCommandService) UpdateUserEmailVerifiedAt(ctx context.Context
139136

140137
// UpdateUserPassword update user password by address
141138
func (service *UserCommandService) UpdateUserPassword(ctx context.Context, data types.UpdateUserPassword) error {
142-
// get user by wallet address
143-
user, err := service.UserQueryRepositoryInterface.SelectUserByWalletAddress(data.WalletAddress)
144-
if err != nil {
145-
return err
146-
}
147-
148-
// compare current password
149-
if !password.CheckPasswordHash(data.CurrentPassword, user.Password) {
150-
return errors.New(apiError.InvalidPassword)
151-
}
152-
153-
hashedPassword, err := password.HashPassword(data.NewPassword)
139+
hashedPassword, err := password.HashPassword(data.Password)
154140
if err != nil {
155141
return err
156142
}
157143

158144
err = service.UserCommandRepositoryInterface.UpdateUserPassword(repositoryTypes.UpdateUserPassword{
159145
WalletAddress: data.WalletAddress,
160-
NewPassword: hashedPassword,
146+
Password: hashedPassword,
161147
})
162148
if err != nil {
163149
return err

module/user/infrastructure/service/types/dto.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type UpdateUser struct {
1818
}
1919

2020
type UpdateUserPassword struct {
21-
WalletAddress string
22-
CurrentPassword string
23-
NewPassword string
21+
WalletAddress string
22+
Password string
2423
}

module/user/interfaces/http/dto.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type UpdateUserEmailVerifiedAtRequest struct {
3131
}
3232

3333
type UpdateUserPasswordRequest struct {
34-
CurrentPassword string `json:"currentPassword" validate:"required"`
35-
NewPassword string `json:"newPassword" validate:"required"`
34+
Password string `json:"password" validate:"required"`
3635
}
3736

3837
type CreateUserResponse struct {

module/user/interfaces/http/rest/UserCommandController.go

+2-29
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,6 @@ func (controller *UserCommandController) UpdateUserByWalletAddress(w http.Respon
202202
return
203203
}
204204

205-
// FIXME: remove this temporary code for allowing demo exploration
206-
if walletAddress == "0xd78F31c1181a305C1Afa5F542fFBE7bda97D5C05" {
207-
response := viewmodels.HTTPResponseVM{
208-
Status: http.StatusUnauthorized,
209-
Success: false,
210-
Message: "For demo purposes only. Contact support to explore the full features.",
211-
ErrorCode: apiError.UnauthorizedAccess,
212-
}
213-
214-
response.JSON(w)
215-
return
216-
}
217-
218205
var request types.UpdateUserRequest
219206

220207
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
@@ -308,19 +295,6 @@ func (controller *UserCommandController) UpdateUserPassword(w http.ResponseWrite
308295
return
309296
}
310297

311-
// FIXME: remove this temporary code for allowing demo exploration
312-
if walletAddress == "0xd78F31c1181a305C1Afa5F542fFBE7bda97D5C05" {
313-
response := viewmodels.HTTPResponseVM{
314-
Status: http.StatusUnauthorized,
315-
Success: false,
316-
Message: "For demo purposes only. Contact support to explore the full features.",
317-
ErrorCode: apiError.UnauthorizedAccess,
318-
}
319-
320-
response.JSON(w)
321-
return
322-
}
323-
324298
var request types.UpdateUserPasswordRequest
325299

326300
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
@@ -363,9 +337,8 @@ func (controller *UserCommandController) UpdateUserPassword(w http.ResponseWrite
363337
}
364338

365339
err = controller.UserCommandServiceInterface.UpdateUserPassword(context.TODO(), serviceTypes.UpdateUserPassword{
366-
WalletAddress: walletAddress,
367-
CurrentPassword: request.CurrentPassword,
368-
NewPassword: request.NewPassword,
340+
WalletAddress: walletAddress,
341+
Password: request.Password,
369342
})
370343
if err != nil {
371344
var httpCode int

0 commit comments

Comments
 (0)