Save hashed PW. Simplify model update. Bugfixes & improvements. Working user-settings & games.
This commit is contained in:
23
auth.go
23
auth.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user