diff --git a/faxSrc/controllers/authentication.go b/faxSrc/controllers/authentication.go index d6f57bf..d6e133e 100644 --- a/faxSrc/controllers/authentication.go +++ b/faxSrc/controllers/authentication.go @@ -11,17 +11,17 @@ import ( "github.com/golang-jwt/jwt/v4" ) -func isAuthenticated(r *http.Request) bool { +func isAuthenticated(r *http.Request) (bool, string) { cookies := r.Cookies() for _, c := range cookies { if c.Name == "token" { // Check if the token exists and if its date is valid expirationTime := time.Now() - return expirationTime.Unix() >= c.Expires.Unix() + return expirationTime.Unix() >= c.Expires.Unix(), c.Value } } - return false + return false, "" } func Authenticate(w http.ResponseWriter, r *http.Request) { diff --git a/faxSrc/controllers/editor.go b/faxSrc/controllers/editor.go index bca8d04..7a1f1d0 100644 --- a/faxSrc/controllers/editor.go +++ b/faxSrc/controllers/editor.go @@ -6,7 +6,8 @@ import ( ) func EditorPage(w http.ResponseWriter, r *http.Request) { - if !isAuthenticated(r) { + authd, _ := isAuthenticated(r) + if !authd { views.LoginPage(w, r) return } diff --git a/faxSrc/controllers/sendFax.go b/faxSrc/controllers/sendFax.go index 62705ef..26f7b52 100644 --- a/faxSrc/controllers/sendFax.go +++ b/faxSrc/controllers/sendFax.go @@ -8,8 +8,7 @@ import ( "io" "log" "net/http" - - "thermalFax/views" + "thermalFax/models" ) type PrintServerResponse struct { @@ -58,11 +57,14 @@ func sendRequestToPrinter(msg string) (PrintServerResponse, error) { // sendFax is a function that receives the data from the fronted and // sends it to the print server func SendFax(w http.ResponseWriter, r *http.Request) { - if !isAuthenticated(r) { - views.LoginPage(w, r) + authd, token := isAuthenticated(r) + if !authd { return } + session, _ := models.GetSession(token) + log.Printf(" | User %s request a fax.", session.User) + data, _ := io.ReadAll(r.Body) log.Printf("| Received Request: %s", data)