@@ -58,8 +58,8 @@ func RegisterUser(context *gin.Context) {
58
58
}
59
59
60
60
// 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
63
63
user .FirstName = userCreationRequest .FirstName
64
64
65
65
stringMatch , requirements , err := utilities .ValidateTextCharacters (user .FirstName )
@@ -90,13 +90,17 @@ func RegisterUser(context *gin.Context) {
90
90
return
91
91
}
92
92
93
- * user .Enabled = true
94
- user .ID = uuid .New ()
95
- * user .ResetExpiration = time .Now ()
93
+ var trueVariable = true
94
+ var now = time .Now ()
96
95
randomString := randstr .String (8 )
97
- * user . VerificationCode = strings .ToUpper (randomString )
96
+ var verificationCode = strings .ToUpper (randomString )
98
97
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
100
104
101
105
// Check if any users exist, if not, make new user admin
102
106
userAmount , err := database .GetAmountOfEnabledUsers ()
@@ -711,6 +715,14 @@ func APIResetPassword(context *gin.Context) {
711
715
return
712
716
}
713
717
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
+
714
726
_ , err = database .GenerateRandomResetCodeForUser (user .ID )
715
727
if err != nil {
716
728
log .Println ("Failed to generate reset code for user during password reset. Error: " + err .Error ())
@@ -730,7 +742,7 @@ func APIResetPassword(context *gin.Context) {
730
742
err = utilities .SendSMTPResetEmail (user )
731
743
if err != nil {
732
744
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. " })
734
746
context .Abort ()
735
747
return
736
748
}
0 commit comments