working commit

This commit is contained in:
2026-02-12 12:00:17 +02:00
parent ae15bddb15
commit b279687623
20 changed files with 639 additions and 192 deletions
+14 -14
View File
@@ -1,10 +1,6 @@
package handler
import (
//"encoding/base64"
//"fmt"
//"strings"
"mstore/app/router"
"mstore/pkg/auxhttp"
)
@@ -18,12 +14,14 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
var handlerFunc router.HandlerFunc
handlerFunc = func(rctx *router.Context) {
authSuccessful, authError := hand.CheckAccess(rctx)
if authSuccessful && authError == nil {
hand.logg.Debugf("Call authorization middleware")
success, username, err := hand.CheckAccess(rctx)
if success && err == nil {
rctx.SetBool(authTag, true)
rctx.SetString(userTag, username)
}
if authError != nil {
hand.logg.Errorf("Authorization middleware error: %v", authError)
if err != nil {
hand.logg.Errorf("Authorization middleware error: %v", err)
}
next.ServeHTTP(rctx)
@@ -31,21 +29,23 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
return handlerFunc
}
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, error) {
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
var err error
var res bool
var success bool
var username string
var password string
authHeader := rctx.GetHeader("Authorization")
if authHeader != "" {
hand.logg.Debugf("Authorization header is %s", authHeader)
username, password, err := auxhttp.ParseBasicAuth(authHeader)
username, password, err = auxhttp.ParseBasicAuth(authHeader)
if err != nil {
return res, err
return success, username, err
}
hand.logg.Debugf("Authorization username is %s:%s", username, password)
}
res = true
success = true
return res, err
return success, username, err
}