WIP: Enrollement MFA avec TOTP

This commit is contained in:
William Bouzourène 2024-12-21 21:54:51 +01:00
parent 274a30480e
commit 53c94a490c
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww
10 changed files with 144 additions and 1 deletions

View file

@ -2,9 +2,11 @@ package helpers
import (
"errors"
"fmt"
"time"
"git.readonly.ch/bouzoure/popvaud-people/models"
"github.com/gofiber/fiber/v2"
"gorm.io/gorm"
)
@ -73,3 +75,23 @@ func UserExistsAndIsActive(id uint) (bool, error) {
return true, nil
}
func GetSessionUserId(c *fiber.Ctx) (uint, error) {
sess, err := GetSessionStore(c)
if err != nil {
return 0, err
}
userid := sess.Get("userid")
if userid == nil {
return 0, fmt.Errorf("no value for key userid in session")
}
switch userid.(type) {
case uint:
default:
return 0, fmt.Errorf("userid value is not of type uint as expected")
}
return userid.(uint), nil
}