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:
3
internal/session/go.mod
Normal file
3
internal/session/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module session
|
||||
|
||||
go 1.21
|
||||
43
internal/session/session.go
Normal file
43
internal/session/session.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user