|
|
@@ -6,6 +6,7 @@ import (
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/gorilla/sessions"
|
|
|
"github.com/porter-dev/porter/api/server/shared/apierrors"
|
|
|
@@ -81,6 +82,34 @@ func (authn *AuthN) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ cancelTokens := func(lastIssueTime time.Time, cancelEmail string, authn *AuthN, session *sessions.Session) bool {
|
|
|
+ if email, ok := session.Values["email"]; ok {
|
|
|
+ if email.(string) == cancelEmail {
|
|
|
+ timeAsUTC := lastIssueTime.UTC()
|
|
|
+ sess, _ := authn.config.Repo.Session().SelectSession(&models.Session{Key: session.ID})
|
|
|
+ if sess.CreatedAt.UTC().Before(timeAsUTC) {
|
|
|
+ _, _ = authn.config.Repo.Session().DeleteSession(sess)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ est, err := time.LoadLocation("EST")
|
|
|
+ if err != nil {
|
|
|
+ authn.handleForbiddenForSession(w, r, fmt.Errorf("error, contact admin"), session)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if cancelTokens(time.Date(2024, 0o1, 16, 18, 35, 0, 0, est), "support@porter.run", authn, session) {
|
|
|
+ authn.handleForbiddenForSession(w, r, fmt.Errorf("error, contact admin"), session)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if cancelTokens(time.Date(2024, 0o1, 16, 18, 35, 0, 0, est), "admin@porter.run", authn, session) {
|
|
|
+ authn.handleForbiddenForSession(w, r, fmt.Errorf("error, contact admin"), session)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if auth, ok := session.Values["authenticated"].(bool); !auth || !ok {
|
|
|
authn.handleForbiddenForSession(w, r, fmt.Errorf("stored cookie was not authenticated"), session)
|
|
|
return
|