Player cache and project structure refactor.
This commit is contained in:
99
pages.go
99
pages.go
@@ -1,99 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"InfantrySkillCalculator/controllers"
|
||||
"InfantrySkillCalculator/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"session"
|
||||
)
|
||||
|
||||
func mainPage(c *gin.Context) {
|
||||
data := map[string]interface{}{
|
||||
"UserRole": controllers.GetUserRoleByCtx(c),
|
||||
}
|
||||
|
||||
err := utils.MainPageTemplates.Execute(c.Writer, data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func loginPage(c *gin.Context) {
|
||||
if auth, ok := session.GetAuthenticated(c); ok && auth {
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
return
|
||||
}
|
||||
|
||||
err := utils.LoginPageTemplates.Execute(c.Writer, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func loginPost(c *gin.Context) {
|
||||
username := c.PostForm("username")
|
||||
password := c.PostForm("password")
|
||||
|
||||
if !checkUserCredentials(username, password) {
|
||||
c.HTML(http.StatusOK, "login_error.html", gin.H{"message": "Ungültige Logindaten!"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := session.SetLoginSession(username, c); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("HX-Redirect", "/")
|
||||
c.String(http.StatusOK, "")
|
||||
}
|
||||
|
||||
func logout(c *gin.Context) {
|
||||
if err := session.InvalidateSession(c); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
}
|
||||
|
||||
func registerPage(c *gin.Context) {
|
||||
if auth, ok := session.GetAuthenticated(c); ok && auth {
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
return
|
||||
}
|
||||
|
||||
err := utils.RegisterPageTemplates.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
|
||||
}
|
||||
|
||||
hashedPassword, err := hashPassword(password)
|
||||
if err != nil {
|
||||
c.HTML(http.StatusOK, "login_error.html", gin.H{"message": "Fehler beim Registrieren!"})
|
||||
return
|
||||
}
|
||||
|
||||
controllers.CreateUser(username, hashedPassword, true, code)
|
||||
|
||||
if err := session.SetLoginSession(username, c); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("HX-Redirect", "/")
|
||||
c.String(http.StatusOK, "")
|
||||
}
|
||||
Reference in New Issue
Block a user