feat: email verification flow (not 100% complete)

This commit is contained in:
Florian Sylvain
2024-05-15 12:04:30 +02:00
parent 37647e60d9
commit c929acd4ab
11 changed files with 126 additions and 24 deletions
+12 -4
View File
@@ -14,17 +14,25 @@ func GetRegisterValidatePage(w http.ResponseWriter, r *http.Request) {
return
}
_, claims, _ := jwtauth.FromContext(r.Context())
userId, _ := claims["user_id"].(uint32)
token, _ := jwtauth.VerifyRequest(
TokenAuth,
r,
jwtauth.TokenFromCookie,
jwtauth.TokenFromHeader,
jwtauth.TokenFromQuery)
user, _ := Container.GetUserUseCase.GetUser(userId)
userId := token.PrivateClaims()["user_id"].(float64)
user, _ := Container.GetUserUseCase.GetUser(uint32(userId))
errorMessage := ""
err := bcrypt.CompareHashAndPassword([]byte(user.VerificationCode), []byte(queryVerificationCode))
if err != nil || user.VerificationExpiration.Before(time.Now()) {
errorMessage = "Verification link is incorrect or has expired."
} else {
// TODO New usecase "UpdateUserUseCase" to update its verification status
_, err := Container.UpdateUserUseCase.UpdateVerificationStatus(user.ID, true)
if err != nil {
errorMessage = "Something went wrong server-side. User account may not exist."
}
}
registerValidateTmpl, _ := Container.GetPageUseCase.GetPage("registerValidate", map[string]interface{}{