attempts at fixing registraiton form
This commit is contained in:
parent
10095f4255
commit
e9d1e12c8d
BIN
data/dk.db
BIN
data/dk.db
Binary file not shown.
@ -41,11 +41,11 @@ func RenderPage(ctx sushi.Ctx, title, tmplPath string, additionalData map[string
|
||||
data := map[string]any{
|
||||
"_title": PageTitle(title),
|
||||
"authenticated": ctx.IsAuthenticated(),
|
||||
"user": ctx.GetCurrentUser(),
|
||||
"csrf": csrf.HiddenField(ctx),
|
||||
"_totaltime": totalTime,
|
||||
"_version": "1.0.0",
|
||||
"_build": "dev",
|
||||
"user": ctx.GetCurrentUser().(*users.User),
|
||||
"_memalloc": m.Alloc / 1024 / 1024,
|
||||
"_errormsg": sess.GetFlashMessage("error"),
|
||||
"_successmsg": sess.GetFlashMessage("success"),
|
||||
|
@ -112,21 +112,26 @@ func processRegister(ctx sushi.Ctx) {
|
||||
"email": email,
|
||||
}
|
||||
|
||||
sess := ctx.GetCurrentSession()
|
||||
|
||||
if err := validateRegistration(username, email, userPassword, confirmPassword); err != nil {
|
||||
fmt.Println("Error occured: " + err.Error())
|
||||
setFlashAndFormData(ctx, err.Error(), formData)
|
||||
ctx.Redirect("/register")
|
||||
return
|
||||
}
|
||||
|
||||
// Check if username already exists
|
||||
if _, err := users.ByUsername(username); err == nil {
|
||||
if _, err := users.ByUsername(username); err != nil {
|
||||
fmt.Println("Username already exists")
|
||||
setFlashAndFormData(ctx, "Username already exists", formData)
|
||||
ctx.Redirect("/register")
|
||||
return
|
||||
}
|
||||
|
||||
// Check if email already exists
|
||||
if _, err := users.ByEmail(email); err == nil {
|
||||
if _, err := users.ByEmail(email); err != nil {
|
||||
fmt.Println("Email already exists")
|
||||
setFlashAndFormData(ctx, "Email already registered", formData)
|
||||
ctx.Redirect("/register")
|
||||
return
|
||||
@ -135,6 +140,7 @@ func processRegister(ctx sushi.Ctx) {
|
||||
// Ensure class ID exists (should always, unless someone modified the form)
|
||||
class, err := classes.Find(classID)
|
||||
if err != nil {
|
||||
fmt.Println("Invalid class ID")
|
||||
setFlashAndFormData(ctx, "Invalid class selected", formData)
|
||||
ctx.Redirect("/register")
|
||||
return
|
||||
@ -175,7 +181,6 @@ func processRegister(ctx sushi.Ctx) {
|
||||
ctx.Login(user.ID, user)
|
||||
|
||||
// Set success message
|
||||
sess := ctx.GetCurrentSession()
|
||||
sess.SetFlash("success", fmt.Sprintf("Greetings, %s!", user.Username))
|
||||
|
||||
ctx.Redirect("/")
|
||||
|
Loading…
x
Reference in New Issue
Block a user