-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9221d9b
commit 5fd5dab
Showing
2 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), "[email protected]", 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), "[email protected]", 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters