Skip to content

Commit 20aa3b8

Browse files
authored
Fixed user reg, reset, verify (#64)
1 parent 6a4718e commit 20aa3b8

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

controllers/user.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func RegisterUser(context *gin.Context) {
5858
}
5959

6060
// Move values from request to object
61-
*user.Email = userCreationRequest.Email
62-
*user.Password = userCreationRequest.Password
61+
user.Email = &userCreationRequest.Email
62+
user.Password = &userCreationRequest.Password
6363
user.FirstName = userCreationRequest.FirstName
6464

6565
stringMatch, requirements, err := utilities.ValidateTextCharacters(user.FirstName)
@@ -90,13 +90,17 @@ func RegisterUser(context *gin.Context) {
9090
return
9191
}
9292

93-
*user.Enabled = true
94-
user.ID = uuid.New()
95-
*user.ResetExpiration = time.Now()
93+
var trueVariable = true
94+
var now = time.Now()
9695
randomString := randstr.String(8)
97-
*user.VerificationCode = strings.ToUpper(randomString)
96+
var verificationCode = strings.ToUpper(randomString)
9897
randomString = randstr.String(8)
99-
*user.ResetCode = strings.ToUpper(randomString)
98+
var resetCode = strings.ToUpper(randomString)
99+
user.Enabled = &trueVariable
100+
user.ID = uuid.New()
101+
user.ResetExpiration = &now
102+
user.VerificationCode = &verificationCode
103+
user.ResetCode = &resetCode
100104

101105
// Check if any users exist, if not, make new user admin
102106
userAmount, err := database.GetAmountOfEnabledUsers()
@@ -711,6 +715,14 @@ func APIResetPassword(context *gin.Context) {
711715
return
712716
}
713717

718+
user, err = database.GetAllUserInformation(user.ID)
719+
if err != nil {
720+
log.Println("Failed to get all user information. Replied with okay 200. Error: " + err.Error())
721+
context.JSON(http.StatusOK, gin.H{"message": "If the user exists, an email with a password reset has been sent."})
722+
context.Abort()
723+
return
724+
}
725+
714726
_, err = database.GenerateRandomResetCodeForUser(user.ID)
715727
if err != nil {
716728
log.Println("Failed to generate reset code for user during password reset. Error: " + err.Error())
@@ -730,7 +742,7 @@ func APIResetPassword(context *gin.Context) {
730742
err = utilities.SendSMTPResetEmail(user)
731743
if err != nil {
732744
log.Println("Failed to send email to user during password reset. Error: " + err.Error())
733-
context.JSON(http.StatusInternalServerError, gin.H{"message": "Error."})
745+
context.JSON(http.StatusInternalServerError, gin.H{"message": "Error. Failed to send e-mail."})
734746
context.Abort()
735747
return
736748
}

web/js/functions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function get_login(cookie) {
9595
} else {
9696
load_page(false);
9797
}
98-
} else if (result.error) {
98+
} else if (result.error && result.error !== "You must verify your account.") {
9999
error(result.error)
100100
showLoggedOutMenu();
101101
return;

0 commit comments

Comments
 (0)