Explorar o código

Merge branch 'beta.3.cli-github-login' of https://github.com/porter-dev/porter into beta.3.metrics

jusrhee %!s(int64=5) %!d(string=hai) anos
pai
achega
feb1a7c462
Modificáronse 1 ficheiros con 16 adicións e 11 borrados
  1. 16 11
      server/router/middleware/auth.go

+ 16 - 11
server/router/middleware/auth.go

@@ -187,23 +187,28 @@ func (auth *Auth) DoesUserHaveProjectAccess(
 		// first check for token
 		tok := auth.getTokenFromRequest(r)
 
+		var userID uint
+
 		if tok != nil && tok.ProjectID == uint(projID) {
 			next.ServeHTTP(w, r)
 			return
-		}
-
-		session, err := auth.store.Get(r, auth.cookieName)
+		} else if tok != nil {
+			userID = tok.IBy
+		} else {
+			session, err := auth.store.Get(r, auth.cookieName)
 
-		if err != nil {
-			http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
-			return
-		}
+			if err != nil {
+				http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
+				return
+			}
 
-		userID, ok := session.Values["user_id"].(uint)
+			sessionUserID, ok := session.Values["user_id"]
+			userID = sessionUserID.(uint)
 
-		if !ok {
-			http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
-			return
+			if !ok {
+				http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
+				return
+			}
 		}
 
 		// get the project