Better flow when trying to send a message but the token is out of date

This commit is contained in:
2024-06-10 22:38:16 +01:00
parent 0c1dd26df4
commit 71fe05f916
2 changed files with 3 additions and 10 deletions
-7
View File
@@ -100,7 +100,6 @@ func createNewSession(w http.ResponseWriter, loginForm models.LoginForm) {
log.Printf(`| {"user": %s, "time": %d}`, loginForm.Username, time.Now().Unix())
w.Header().Add("HX-Redirect", "/editor")
}
func updateSession(w http.ResponseWriter, loginForm models.LoginForm,
@@ -108,7 +107,6 @@ func updateSession(w http.ResponseWriter, loginForm models.LoginForm,
localUserSession := models.GetSession(sessionCookie.Value)
if localUserSession == nil {
// Just create a new session in this case
log.Println("| User has session key not present locally")
createNewSession(w, loginForm)
return
}
@@ -121,7 +119,6 @@ func updateSession(w http.ResponseWriter, loginForm models.LoginForm,
}
http.SetCookie(w, &cookie)
log.Println("| User is being sent to ", localUserSession.Wants)
w.Header().Set("HX-Redirect", localUserSession.Wants)
}
@@ -137,7 +134,6 @@ func Authenticate(w http.ResponseWriter, r *http.Request) {
}
if !models.ValidateCredentials(&loginForm) {
log.Println("| Invalid credentials.")
w.Header().Add("HX-Trigger", `{"wrongCredentials":"Wrong Credentials"}`)
return
}
@@ -175,13 +171,10 @@ func saveSessionState(r *http.Request) {
}
cache.Data[tok].Wants = r.RequestURI
log.Println("| User wants to go to ", cache.Data[tok].Wants)
}
}
func reauth(w http.ResponseWriter, r *http.Request) {
log.Println("| User wants to request something but authentication has expired")
saveSessionState(r)
w.Header().Set("HX-Redirect", "/login")
w.Header().Set("HX-Push-Url", "true")
+3 -3
View File
@@ -70,10 +70,10 @@ func sendRequestToPrinter(msg string) (PrintServerResponse, error) {
func SendFax(w http.ResponseWriter, r *http.Request) {
authd, token := isAuthenticated(r)
if !authd {
// We don't do a reauth here so that the user is actually sent to the
// login page and then to the /editor by default
// We don't do a reauth here so we do a simple refresh and let the /editor controller
// take care of it on the following request
// - We will have to make it be clear that the message was not sent tho
w.Header().Set("HX-Redirect", "/login")
w.Header().Set("HX-Refresh", "true")
return
}