40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package useCases
|
|
|
|
import (
|
|
"RenewCMS/internal/domain/hash"
|
|
"RenewCMS/internal/domain/user"
|
|
"time"
|
|
)
|
|
|
|
type UpdateUserUseCase struct {
|
|
userRepository user.Repository
|
|
hasher hash.Hasher
|
|
}
|
|
|
|
func NewUpdateUserUseCase(userRepository user.Repository, hasher hash.Hasher) *UpdateUserUseCase {
|
|
return &UpdateUserUseCase{userRepository, hasher}
|
|
}
|
|
|
|
func (g *UpdateUserUseCase) UpdateVerificationStatus(userId uint32, isVerified bool) (user.User, error) {
|
|
return g.userRepository.UpdateVerificationStatus(userId, isVerified)
|
|
}
|
|
|
|
func (g *UpdateUserUseCase) UpdatePasswordResetCode(userId uint32, code string, expiration time.Time) (user.User, error) {
|
|
if code == "" {
|
|
return g.userRepository.UpdatePasswordResetCode(userId, "", expiration)
|
|
}
|
|
hashedCode, err := g.hasher.Hash(code)
|
|
if err != nil {
|
|
return user.User{}, err
|
|
}
|
|
return g.userRepository.UpdatePasswordResetCode(userId, hashedCode, expiration)
|
|
}
|
|
|
|
func (g *UpdateUserUseCase) UpdatePassword(userId uint32, password string) (user.User, error) {
|
|
hashedPassword, err := g.hasher.Hash(password)
|
|
if err != nil {
|
|
return user.User{}, err
|
|
}
|
|
return g.userRepository.UpdatePassword(userId, hashedPassword)
|
|
}
|