Save hashed PW. Simplify model update. Bugfixes & improvements. Working user-settings & games.

This commit is contained in:
MaxJa4
2024-01-18 19:00:32 +01:00
parent f8ac93f163
commit f2ab72ba1e
20 changed files with 310 additions and 113 deletions

23
auth.go
View File

@@ -1,8 +1,9 @@
package main
import (
"InfrantrySkillCalculator/models"
"InfrantrySkillCalculator/utils"
"InfantrySkillCalculator/controllers"
"InfantrySkillCalculator/models"
"InfantrySkillCalculator/utils"
"errors"
"fmt"
"github.com/gin-gonic/gin"
@@ -34,14 +35,7 @@ func getUserPassword(username string) (string, error) {
return "", err
}
var hashedPW string
hashedPW, err := hashPassword(user.Password)
if err != nil {
log.Fatal(err)
return "", err
}
return hashedPW, nil
return user.Password, nil
}
func hashPassword(password string) (string, error) {
@@ -54,8 +48,13 @@ func hashPassword(password string) (string, error) {
func AuthRequired() gin.HandlerFunc {
return func(c *gin.Context) {
session, _ := store.Get(c.Request, LoginSessionName)
if auth, ok := session.Values["authenticated"].(bool); !ok || !auth {
session, _ := utils.Store.Get(c.Request, utils.LoginSessionName)
if auth, ok := session.Values["authenticated"].(bool); !ok || !auth || !controllers.IsUserEnabled(session.Values["username"].(string)) {
session.Options.MaxAge = -1
err := session.Save(c.Request, c.Writer)
if err != nil {
log.Fatal(err)
}
c.Redirect(http.StatusFound, "/login")
c.Abort()
return