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:
MaxJa4
2024-01-21 00:49:20 +01:00
parent 069d76520e
commit 16d782fbe8
41 changed files with 1154 additions and 203 deletions

View File

@@ -0,0 +1,43 @@
package session
import (
"github.com/gin-gonic/gin"
"github.com/gorilla/sessions"
)
var store = sessions.NewCookieStore([]byte("f0q0qew0!)§(ds9713lsda231"))
const LoginSessionName = "session"
func GetUsername(c *gin.Context) (string, bool) {
session, _ := getSession(c)
username, ok := session.Values["username"].(string)
return username, ok
}
func GetAuthenticated(c *gin.Context) (bool, bool) {
session, _ := getSession(c)
auth, ok := session.Values["authenticated"].(bool)
return auth, ok
}
func getSession(c *gin.Context) (*sessions.Session, error) {
return store.Get(c.Request, LoginSessionName)
}
func InvalidateSession(c *gin.Context) error {
session, _ := getSession(c)
session.Options.MaxAge = -1
err := session.Save(c.Request, c.Writer)
return err
}
func SetLoginSession(username string, c *gin.Context) error {
session, _ := getSession(c)
session.Values["authenticated"] = true
session.Values["username"] = username
err := session.Save(c.Request, c.Writer)
return err
}