refactor: use context fom middleware in handlers

This commit is contained in:
Stavros
2025-08-25 14:19:52 +03:00
parent ace22acdb2
commit e1d8ce3cb5
11 changed files with 142 additions and 57 deletions

View File

@@ -141,7 +141,25 @@ func (h *Handlers) TOTPHandler(c *gin.Context) {
log.Debug().Msg("Checking totp")
// Get user context
userContext := h.Hooks.UseUserContext(c)
userContextValue, exists := c.Get("context")
if !exists {
c.JSON(401, gin.H{
"status": 401,
"message": "Unauthorized",
})
return
}
userContext, ok := userContextValue.(*types.UserContext)
if !ok {
c.JSON(401, gin.H{
"status": 401,
"message": "Unauthorized",
})
return
}
// Check if we have a user
if userContext.Username == "" {
@@ -157,7 +175,7 @@ func (h *Handlers) TOTPHandler(c *gin.Context) {
user := h.Auth.GetLocalUser(userContext.Username)
// Check if totp is correct
ok := totp.Validate(totpReq.Code, user.TotpSecret)
ok = totp.Validate(totpReq.Code, user.TotpSecret)
if !ok {
log.Debug().Msg("Totp incorrect")