mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
refac: useless little refactor for clean verificationCode placement
This commit is contained in:
@@ -23,9 +23,6 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link text-body-tertiary text-decoration-underline" href="https://www.paypal.com/donate/?hosted_button_id=S6LUFUYK84CYY">support me!</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link disconnect-link" href="/logout">Log out</a>
|
<a class="nav-link disconnect-link" href="/logout">Log out</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/jwtauth/v5"
|
"github.com/go-chi/jwtauth/v5"
|
||||||
"github.com/google/uuid"
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -102,19 +101,6 @@ func GetUserFromCredentials(credentials LoginCredentials) (user.User, error) {
|
|||||||
return dbUser, nil
|
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) {
|
func login(w http.ResponseWriter, r *http.Request) {
|
||||||
var credentials LoginCredentials
|
var credentials LoginCredentials
|
||||||
|
|
||||||
@@ -161,8 +147,11 @@ func register(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationCode := uuid.NewString()
|
createdUser, err := api.Container.CreateUserUseCase.CreateUser(useCases.CreateUserCommand{
|
||||||
createdUser, err := GetNewUser(credentials, verificationCode)
|
Username: credentials.Username,
|
||||||
|
Password: credentials.Password,
|
||||||
|
Email: credentials.Email,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ package pages
|
|||||||
import (
|
import (
|
||||||
"RenewCMS/api"
|
"RenewCMS/api"
|
||||||
"RenewCMS/api/controllers/auth"
|
"RenewCMS/api/controllers/auth"
|
||||||
|
"RenewCMS/useCases"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RegisterPageError struct {
|
type RegisterPageError struct {
|
||||||
@@ -80,8 +79,11 @@ func PostRegisterPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationCode := uuid.NewString()
|
createdUser, err := api.Container.CreateUserUseCase.CreateUser(useCases.CreateUserCommand{
|
||||||
createdUser, err := auth.GetNewUser(credentials, verificationCode)
|
Username: credentials.Username,
|
||||||
|
Password: credentials.Password,
|
||||||
|
Email: credentials.Email,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Method = http.MethodGet
|
r.Method = http.MethodGet
|
||||||
GetRegisterPageHandler(&RegisterPage{
|
GetRegisterPageHandler(&RegisterPage{
|
||||||
@@ -98,7 +100,7 @@ func PostRegisterPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_ = api.Container.SendMailUseCase.SendMail(createdUser.Email, "mailValidation", map[string]string{
|
_ = api.Container.SendMailUseCase.SendMail(createdUser.Email, "mailValidation", map[string]string{
|
||||||
"Host": os.Getenv("HOST"),
|
"Host": os.Getenv("HOST"),
|
||||||
"VerificationCode": verificationCode,
|
"VerificationCode": createdUser.VerificationCode,
|
||||||
})
|
})
|
||||||
|
|
||||||
_ = auth.SetJwtCookie(&w, createdUser.ID)
|
_ = auth.SetJwtCookie(&w, createdUser.ID)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package useCases
|
|||||||
import (
|
import (
|
||||||
"RenewCMS/domain/gateways"
|
"RenewCMS/domain/gateways"
|
||||||
"RenewCMS/domain/user"
|
"RenewCMS/domain/user"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateUserUseCase struct {
|
type CreateUserUseCase struct {
|
||||||
@@ -13,7 +15,6 @@ type CreateUserCommand struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Email string
|
Email string
|
||||||
VerificationCode string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCreateUserUseCase(userRepository gateways.IUserRepository) *CreateUserUseCase {
|
func NewCreateUserUseCase(userRepository gateways.IUserRepository) *CreateUserUseCase {
|
||||||
@@ -26,6 +27,6 @@ func (g *CreateUserUseCase) CreateUser(createUser CreateUserCommand) (user.User,
|
|||||||
createUser.Password,
|
createUser.Password,
|
||||||
"",
|
"",
|
||||||
createUser.Email,
|
createUser.Email,
|
||||||
createUser.VerificationCode,
|
uuid.NewString(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user