Bugfixes. Optimizations/refactor. Add redis for player-cache. Add docker files. Replace sqlite dep. Single-Calc for existing players. Game-Metrics in JSON.
This commit is contained in:
27
pages.go
27
pages.go
@@ -2,10 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"InfantrySkillCalculator/controllers"
|
||||
"InfantrySkillCalculator/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"session"
|
||||
)
|
||||
|
||||
func mainPage(c *gin.Context) {
|
||||
@@ -20,9 +20,7 @@ func mainPage(c *gin.Context) {
|
||||
}
|
||||
|
||||
func loginPage(c *gin.Context) {
|
||||
session, _ := utils.Store.Get(c.Request, utils.LoginSessionName)
|
||||
|
||||
if auth, ok := session.Values["authenticated"].(bool); ok && auth {
|
||||
if auth, ok := session.GetAuthenticated(c); ok && auth {
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
return
|
||||
}
|
||||
@@ -42,11 +40,7 @@ func loginPost(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
session, _ := utils.Store.Get(c.Request, utils.LoginSessionName)
|
||||
session.Values["authenticated"] = true
|
||||
session.Values["username"] = username
|
||||
err := session.Save(c.Request, c.Writer)
|
||||
if err != nil {
|
||||
if err := session.SetLoginSession(username, c); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
@@ -56,10 +50,7 @@ func loginPost(c *gin.Context) {
|
||||
}
|
||||
|
||||
func logout(c *gin.Context) {
|
||||
session, _ := utils.Store.Get(c.Request, utils.LoginSessionName)
|
||||
session.Values["authenticated"] = false
|
||||
err := session.Save(c.Request, c.Writer)
|
||||
if err != nil {
|
||||
if err := session.InvalidateSession(c); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
@@ -68,9 +59,7 @@ func logout(c *gin.Context) {
|
||||
}
|
||||
|
||||
func registerPage(c *gin.Context) {
|
||||
session, _ := utils.Store.Get(c.Request, utils.LoginSessionName)
|
||||
|
||||
if auth, ok := session.Values["authenticated"].(bool); ok && auth {
|
||||
if auth, ok := session.GetAuthenticated(c); ok && auth {
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
return
|
||||
}
|
||||
@@ -99,11 +88,7 @@ func registerPost(c *gin.Context) {
|
||||
|
||||
controllers.CreateUser(username, hashedPassword, true, code)
|
||||
|
||||
session, _ := utils.Store.Get(c.Request, utils.LoginSessionName)
|
||||
session.Values["authenticated"] = true
|
||||
session.Values["username"] = username
|
||||
err = session.Save(c.Request, c.Writer)
|
||||
if err != nil {
|
||||
if err := session.SetLoginSession(username, c); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user