mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
feat: email verification flow (not 100% complete)
This commit is contained in:
@@ -44,10 +44,11 @@ func (u *UserRepository) Create(user domain.User) (domain.User, error) {
|
||||
hashedVerificationCode, _ := bcrypt.GenerateFromPassword([]byte(user.VerificationCode), 12)
|
||||
|
||||
creationResult := u.db.Create(&entity.User{
|
||||
Username: user.Username,
|
||||
Password: string(hashedPassword),
|
||||
Email: user.Email,
|
||||
VerificationCode: string(hashedVerificationCode),
|
||||
Username: user.Username,
|
||||
Password: string(hashedPassword),
|
||||
Email: user.Email,
|
||||
VerificationCode: string(hashedVerificationCode),
|
||||
VerificationExpiration: user.VerificationExpiration,
|
||||
})
|
||||
if creationResult.Error != nil {
|
||||
return domain.User{}, creationResult.Error
|
||||
@@ -82,4 +83,20 @@ func (u *UserRepository) GetByUsername(username string) (domain.User, error) {
|
||||
return mapUserToDomain(user), nil
|
||||
}
|
||||
|
||||
func (u *UserRepository) UpdateVerificationStatus(userId uint32, isVerified bool) (domain.User, error) {
|
||||
var user entity.User
|
||||
err := u.db.Model(&entity.User{}).First(&user, userId).Error
|
||||
if err != nil {
|
||||
return domain.User{}, err
|
||||
}
|
||||
|
||||
user.IsVerified = isVerified
|
||||
err = u.db.Save(&user).Error
|
||||
if err != nil {
|
||||
return domain.User{}, err
|
||||
}
|
||||
|
||||
return mapUserToDomain(user), nil
|
||||
}
|
||||
|
||||
var _ gateways.IUserRepository = &UserRepository{}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<h1>GohCMS</h1>
|
||||
<h2>Login</h2>
|
||||
</div>
|
||||
<form action="login" class="" method="POST">
|
||||
<form action="login" method="POST">
|
||||
<div class="d-flex flex-column gap-4">
|
||||
<div class="form-floating">
|
||||
<input class="form-control {{ if .PageError.IsError }} is-invalid {{ end }}"
|
||||
|
||||
@@ -1,27 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>GohCMS | Setup</title>
|
||||
{{.Head}}
|
||||
<title>GohCMS | Setup</title>
|
||||
{{.Head}}
|
||||
|
||||
<style>
|
||||
<style>
|
||||
.form-container {
|
||||
max-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
</head>
|
||||
<body class="d-flex min-vh-100 vw-100 justify-content-center align-items-center text-dark">
|
||||
<div class="container">
|
||||
<div class="d-flex flex-column gap-5 m-auto form-container">
|
||||
<div>
|
||||
<h1>GohCMS</h1>
|
||||
<h2>E-mail verification</h2>
|
||||
</div>
|
||||
<p>Verifying your e-mail, please wait...</p>
|
||||
</div>
|
||||
<div class="d-flex flex-column gap-5 m-auto form-container">
|
||||
<div>
|
||||
<h1>GohCMS</h1>
|
||||
<h2>E-mail verification</h2>
|
||||
</div>
|
||||
{{ if .PageError.IsError }}
|
||||
<p>{{.PageError.Message}}</p>
|
||||
{{ else }}
|
||||
<p>Your e-mail was successfully validated!</p>
|
||||
<form action="../home" method="get" class="d-flex">
|
||||
<button class="btn btn-primary w-100" type="submit">
|
||||
<span class="visually-hidden spinner-border spinner-border-sm"
|
||||
role="status"></span>
|
||||
<span>Continue</span>
|
||||
</button>
|
||||
</form>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const button = document.querySelector("button")
|
||||
|
||||
function setButtonLoading() {
|
||||
button.classList.add("disabled")
|
||||
button.querySelector("button > span + span").classList.add("visually-hidden")
|
||||
button.querySelector("button > span:first-child").classList.remove("visually-hidden")
|
||||
}
|
||||
|
||||
function onSubmit(event) {
|
||||
setButtonLoading()
|
||||
}
|
||||
|
||||
window.addEventListener('submit', onSubmit)
|
||||
button.addEventListener('click', onSubmit)
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user