refac: useless little refactor for clean verificationCode placement

This commit is contained in:
Florian Sylvain
2025-12-09 22:27:59 +01:00
parent d7ee0a488c
commit 0238c7511d
4 changed files with 18 additions and 29 deletions
+5 -16
View File
@@ -11,7 +11,6 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/jwtauth/v5"
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
)
@@ -102,19 +101,6 @@ func GetUserFromCredentials(credentials LoginCredentials) (user.User, error) {
return dbUser, nil
}
func GetNewUser(newUserCredentials RegisterCredentials, verificationCode string) (user.User, error) {
createdUser, err := api.Container.CreateUserUseCase.CreateUser(useCases.CreateUserCommand{
Username: newUserCredentials.Username,
Password: newUserCredentials.Password,
Email: newUserCredentials.Email,
VerificationCode: verificationCode,
})
if err != nil {
return user.User{}, err
}
return createdUser, nil
}
func login(w http.ResponseWriter, r *http.Request) {
var credentials LoginCredentials
@@ -161,8 +147,11 @@ func register(w http.ResponseWriter, r *http.Request) {
return
}
verificationCode := uuid.NewString()
createdUser, err := GetNewUser(credentials, verificationCode)
createdUser, err := api.Container.CreateUserUseCase.CreateUser(useCases.CreateUserCommand{
Username: credentials.Username,
Password: credentials.Password,
Email: credentials.Email,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
+7 -5
View File
@@ -3,10 +3,9 @@ package pages
import (
"RenewCMS/api"
"RenewCMS/api/controllers/auth"
"RenewCMS/useCases"
"net/http"
"os"
"github.com/google/uuid"
)
type RegisterPageError struct {
@@ -80,8 +79,11 @@ func PostRegisterPage(w http.ResponseWriter, r *http.Request) {
return
}
verificationCode := uuid.NewString()
createdUser, err := auth.GetNewUser(credentials, verificationCode)
createdUser, err := api.Container.CreateUserUseCase.CreateUser(useCases.CreateUserCommand{
Username: credentials.Username,
Password: credentials.Password,
Email: credentials.Email,
})
if err != nil {
r.Method = http.MethodGet
GetRegisterPageHandler(&RegisterPage{
@@ -98,7 +100,7 @@ func PostRegisterPage(w http.ResponseWriter, r *http.Request) {
_ = api.Container.SendMailUseCase.SendMail(createdUser.Email, "mailValidation", map[string]string{
"Host": os.Getenv("HOST"),
"VerificationCode": verificationCode,
"VerificationCode": createdUser.VerificationCode,
})
_ = auth.SetJwtCookie(&w, createdUser.ID)