Add activation-codes and registration. Added tooltips. Added player-score-cache-display in mainpage.

This commit is contained in:
MaxJa4
2024-01-17 12:21:48 +01:00
parent 2a8c53ab56
commit 7e3c02e37e
18 changed files with 234 additions and 36 deletions

View File

@@ -94,3 +94,48 @@ func logout(c *gin.Context) {
c.Redirect(http.StatusFound, "/login")
}
func registerPage(c *gin.Context) {
session, _ := store.Get(c.Request, LoginSessionName)
if auth, ok := session.Values["authenticated"].(bool); ok && auth {
c.Redirect(http.StatusFound, "/")
return
}
tmpl, err := template.ParseFiles([]string{"./templates/register.html", "./templates/components/header.html"}...)
if err != nil {
log.Fatal(err)
}
err = tmpl.Execute(c.Writer, nil)
if err != nil {
log.Fatal(err)
}
}
func registerPost(c *gin.Context) {
username := c.PostForm("username")
password := c.PostForm("password")
code := c.PostForm("code")
if !isValidCode(code) {
c.HTML(http.StatusOK, "login_error.html", gin.H{"message": "Ungültiger Aktivierungscode!"})
return
}
user := models.User{Username: username, Password: password, Enabled: true}
models.DB.Create(&user)
session, _ := store.Get(c.Request, LoginSessionName)
session.Values["authenticated"] = true
session.Values["username"] = username
err := session.Save(c.Request, c.Writer)
if err != nil {
c.JSON(http.StatusInternalServerError, nil)
return
}
c.Header("HX-Redirect", "/")
c.String(http.StatusOK, "")
}