Fixed more org related functionality

This commit is contained in:
frikky
2020-10-31 09:11:00 +01:00
parent fdba86f9c3
commit a6a5bc9d30
10 changed files with 405 additions and 247 deletions
+20 -3
View File
@@ -308,7 +308,18 @@ class AppBase:
print("DATA: %s\n" % data) print("DATA: %s\n" % data)
return parse_wrapper(data) return parse_wrapper(data)
# Looks for parantheses to grab special cases within a string, e.g:
# int(1) lower(HELLO) or length(what's the length)
# FIXME:
# There is an issue in here where it returns data wrong. Example:
# Authorization=Bearer authkey
# =
# Authorization=Bearer authkey
# ^ Double space.
def parse_wrapper_start(data): def parse_wrapper_start(data):
if "(" not in data or ")" not in data:
return data
newdata = [] newdata = []
newstring = "" newstring = ""
record = True record = True
@@ -337,7 +348,7 @@ class AppBase:
if len(newstring) > 0: if len(newstring) > 0:
newdata.append(newstring) newdata.append(newstring)
#print(newdata) print("Newdata: ", newdata)
parsedlist = [] parsedlist = []
non_string = False non_string = False
for item in newdata: for item in newdata:
@@ -348,17 +359,20 @@ class AppBase:
parsedlist.append(ret) parsedlist.append(ret)
if len(parsedlist) > 0 and not non_string: if len(parsedlist) > 0 and not non_string:
print("Returning parsed list: ", parsedlist)
return " ".join(parsedlist) return " ".join(parsedlist)
elif len(parsedlist) == 1 and non_string: elif len(parsedlist) == 1 and non_string:
return parsedlist[0] return parsedlist[0]
else: else:
#print("Casting back to string because multi: ", parsedlist) print("Casting back to string because multi: ", parsedlist)
newlist = [] newlist = []
for item in parsedlist: for item in parsedlist:
try: try:
newlist.append(str(item)) newlist.append(str(item))
except ValueError: except ValueError:
newlist.append("parsing_error") newlist.append("parsing_error")
# Does this create the issue?
return " ".join(newlist) return " ".join(newlist)
# Parses JSON loops and such down to the item you're looking for # Parses JSON loops and such down to the item you're looking for
@@ -989,6 +1003,7 @@ class AppBase:
print("Normal parsing (not looping) with data %s" % value) print("Normal parsing (not looping) with data %s" % value)
value = parse_wrapper_start(value) value = parse_wrapper_start(value)
print("POST data value: %s" % value)
params[parameter["name"]] = value params[parameter["name"]] = value
multi_parameters[parameter["name"]] = value multi_parameters[parameter["name"]] = value
@@ -1019,8 +1034,9 @@ class AppBase:
#for i in range(calltimes): #for i in range(calltimes):
if not multiexecution: if not multiexecution:
print("APP_SDK DONE: Starting NORMAL execution of function") print("APP_SDK DONE: Starting NORMAL execution of function")
print("Running with params %s" % params)
newres = await func(**params) newres = await func(**params)
#print("NEWRES: ", newres) print("Return from execution: %s" % newres)
if isinstance(newres, str): if isinstance(newres, str):
result += newres result += newres
else: else:
@@ -1101,6 +1117,7 @@ class AppBase:
print("Running with params %s" % baseparams) print("Running with params %s" % baseparams)
ret = await func(**baseparams) ret = await func(**baseparams)
print("Return from execution: %s" % ret)
if isinstance(ret, dict) or isinstance(ret, list): if isinstance(ret, dict) or isinstance(ret, list):
results.append(ret) results.append(ret)
json_object = True json_object = True
+245 -158
View File
@@ -390,6 +390,7 @@ type Hook struct {
Status string `json:"status" datastore:"status"` Status string `json:"status" datastore:"status"`
Workflows []string `json:"workflows" datastore:"workflows"` Workflows []string `json:"workflows" datastore:"workflows"`
Running bool `json:"running" datastore:"running"` Running bool `json:"running" datastore:"running"`
OrgId string `json:"org_id" datastore:"org_id"`
} }
func createFileFromFile(ctx context.Context, bucket *storage.BucketHandle, remotePath, localPath string) error { func createFileFromFile(ctx context.Context, bucket *storage.BucketHandle, remotePath, localPath string) error {
@@ -689,47 +690,14 @@ func handleApiAuthentication(resp http.ResponseWriter, request *http.Request) (U
authorization = authorizationArr[0] authorization = authorizationArr[0]
} }
_ = authorization _ = authorization
//if item, err := memcache.Get(ctx, authorization); err == memcache.ErrCacheMiss {
// // Doesn't exist :(
// log.Printf("Couldn't find %s in cache!", authorization)
// return User{}, err
//} else if err != nil {
// log.Printf("Error getting item: %v", err)
// return User{}, err
//} else {
// log.Printf("%#v", item.Value)
// var Userdata User
// log.Printf("Deleting key %s", authorization)
// memcache.Delete(ctx, authorization)
// err = json.Unmarshal(item.Value, &Userdata)
// if err == nil {
// return Userdata, nil
// }
// return User{}, err
//}
} }
c, err := request.Cookie("session_token") c, err := request.Cookie("session_token")
if err == nil { if err == nil {
//if item, err := memcache.Get(ctx, c.Value); err == memcache.ErrCacheMiss {
// // Not in cache
//} else if err != nil {
// log.Printf("Error getting item: %v", err)
//} else {
// var Userdata User
// err = json.Unmarshal(item.Value, &Userdata)
// if err == nil {
// return Userdata, nil
// }
//}
sessionToken := c.Value sessionToken := c.Value
session, err := getSession(ctx, sessionToken) session, err := getSession(ctx, sessionToken)
if err != nil { if err != nil {
log.Printf("Session %s doesn't exist (api auth): %s", sessionToken, err) log.Printf("Session %s doesn't exist (session auth): %s", sessionToken, err)
return User{}, err return User{}, err
} }
@@ -865,7 +833,7 @@ func deleteUser(resp http.ResponseWriter, request *http.Request) {
return return
} }
user, userErr := handleApiAuthentication(resp, request) userInfo, userErr := handleApiAuthentication(resp, request)
if userErr != nil { if userErr != nil {
log.Printf("Api authentication failed in edit workflow: %s", userErr) log.Printf("Api authentication failed in edit workflow: %s", userErr)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -873,8 +841,8 @@ func deleteUser(resp http.ResponseWriter, request *http.Request) {
return return
} }
if user.Role != "admin" { if userInfo.Role != "admin" {
log.Printf("Wrong user (%s) when deleting - must be admin", user.Username) log.Printf("Wrong user (%s) when deleting - must be admin", userInfo.Username)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Must be admin"}`)) resp.Write([]byte(`{"success": false, "reason": "Must be admin"}`))
return return
@@ -892,46 +860,57 @@ func deleteUser(resp http.ResponseWriter, request *http.Request) {
userId = location[4] userId = location[4]
} }
if userId == user.Id { if userId == userInfo.Id {
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Can't deactivate yourself"}`)) resp.Write([]byte(`{"success": false, "reason": "Can't deactivate yourself"}`))
return return
} }
ctx := context.Background() ctx := context.Background()
q := datastore.NewQuery("Users").Filter("id =", userId) foundUser, err := getUser(ctx, userId)
var users []User
_, err := dbclient.GetAll(ctx, q, &users)
if err != nil { if err != nil {
log.Printf("Error getting users apikey (deleteuser): %s", err) log.Printf("Can't find user %s (delete user): %s", userId, err)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Failed getting users for verification"}`)) resp.Write([]byte(fmt.Sprintf(`{"success": false}`)))
return return
} }
if len(users) != 1 { orgFound := false
log.Printf("Found too many users!") if userInfo.ActiveOrg.Id == foundUser.ActiveOrg.Id {
resp.WriteHeader(500) orgFound = true
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Backend error: too many or too few users with id %s: %d"}`, userId, len(users)))) } else {
log.Printf("FoundUser: %#v", foundUser.Orgs)
for _, item := range foundUser.Orgs {
if item == userInfo.ActiveOrg.Id {
orgFound = true
break
}
}
}
if !orgFound {
log.Printf("User %s is admin, but can't delete users outside their own org.", userInfo.Id)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Can't change users outside your org."}`)))
return return
} }
// Invert. No user deletion. // Invert. No user deletion.
if users[0].Active { if foundUser.Active {
users[0].Active = false foundUser.Active = false
} else { } else {
users[0].Active = true foundUser.Active = true
} }
err = setUser(ctx, &users[0]) err = setUser(ctx, foundUser)
if err != nil { if err != nil {
log.Printf("Failed swapping active for user %s (%s)", users[0].Username, users[0].Id) log.Printf("Failed swapping active for user %s (%s)", foundUser, foundUser.Username, foundUser.Id)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": true"}`))) resp.Write([]byte(fmt.Sprintf(`{"success": false}`)))
return return
} }
log.Printf("Successfully inverted %s", users[0].Username) log.Printf("Successfully inverted %s", foundUser.Username)
resp.WriteHeader(200) resp.WriteHeader(200)
resp.Write([]byte(`{"success": true}`)) resp.Write([]byte(`{"success": true}`))
@@ -1091,7 +1070,7 @@ func handleSetEnvironments(resp http.ResponseWriter, request *http.Request) {
} }
for _, item := range newEnvironments { for _, item := range newEnvironments {
if item.OrgId == "" { if item.OrgId != user.ActiveOrg.Id {
item.OrgId = user.ActiveOrg.Id item.OrgId = user.ActiveOrg.Id
} }
@@ -1327,51 +1306,53 @@ func handleLogout(resp http.ResponseWriter, request *http.Request) {
return return
} }
// Check cookie userInfo, err := handleApiAuthentication(resp, request)
c, err := request.Cookie("session_token")
if err != nil { if err != nil {
resp.WriteHeader(200) log.Printf("Api authentication failed in handleLogout: %s", err)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
return
} else {
log.Printf("Session cookie is set!")
}
var Userdata User
ctx := context.Background()
//item, err := memcache.Get(ctx, c.Value)
sessionToken := ""
//// Memcache handling for logout
//if err == nil {
// err = json.Unmarshal(item.Value, &Userdata)
// if err != nil {
// log.Printf("Failed unmarshaling: %s", err)
// resp.WriteHeader(401)
// resp.Write([]byte(fmt.Sprintf(`{"success": false}`)))
// return
// }
// sessionToken = Userdata.Session
//} else {
// // Validate with User
sessionToken = c.Value
session, err := getSession(ctx, sessionToken)
if err != nil {
log.Printf("Session %s doesn't exist (logout): %s", session.Session, err)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": ""}`)) resp.Write([]byte(`{"success": false}`))
return return
} }
ctx := context.Background()
session, err := getSession(ctx, userInfo.Session)
if err != nil {
log.Printf("Session %#v doesn't exist: %s", session, err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "No session"}`))
return
}
// Check cookie
//c, err := request.Cookie("session_token")
//if err != nil {
// resp.WriteHeader(200)
// resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
// return
//} else {
// log.Printf("Session cookie is set to %s!", c.Value)
//}
//var Userdata User
//ctx := context.Background()
//sessionToken = c.Value
//session, err := getSession(ctx, sessionToken)
//if err != nil {
// log.Printf("Session %s doesn't exist (logout): %s", sessionToken, err)
// resp.WriteHeader(401)
// resp.Write([]byte(`{"success": false, "reason": "Couldn't find your session"}`))
// return
//}
// Get session first // Get session first
// Should basically never happen // Should basically never happen
_, err = getUser(ctx, session.Id) //_, err = getUser(ctx, session.Id)
if err != nil { //if err != nil {
log.Printf("Username %s doesn't exist (logout): %s", session.Username, err) // log.Printf("Username %s doesn't exist (logout): %s", session.Username, err)
resp.WriteHeader(401) // resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`)) // resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`))
return // return
} //}
// Userdata = *tmpdata // Userdata = *tmpdata
//} //}
@@ -1379,7 +1360,7 @@ func handleLogout(resp http.ResponseWriter, request *http.Request) {
// FIXME // FIXME
// Session might delete someone elses here? // Session might delete someone elses here?
// No need to think about before possible scale..? // No need to think about before possible scale..?
err = SetSession(ctx, Userdata, "") err = SetSession(ctx, userInfo, "")
if err != nil { if err != nil {
log.Printf("Error removing session for: %s", err) log.Printf("Error removing session for: %s", err)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -1387,16 +1368,16 @@ func handleLogout(resp http.ResponseWriter, request *http.Request) {
return return
} }
err = DeleteKey(ctx, "sessions", sessionToken) err = DeleteKey(ctx, "sessions", userInfo.Session)
if err != nil { if err != nil {
log.Printf("Error deleting key %s for %s: %s", c.Value, Userdata.Username, err) log.Printf("Error deleting key %s for %s: %s", userInfo.Session, userInfo.Username, err)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`)) resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`))
return return
} }
Userdata.Session = "" userInfo.Session = ""
err = setUser(ctx, &Userdata) err = setUser(ctx, &userInfo)
if err != nil { if err != nil {
log.Printf("Failed updating user: %s", err) log.Printf("Failed updating user: %s", err)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -1405,10 +1386,10 @@ func handleLogout(resp http.ResponseWriter, request *http.Request) {
} }
//memcache.Delete(request.Context(), sessionToken) //memcache.Delete(request.Context(), sessionToken)
//http.SetCookie(resp, c)
resp.WriteHeader(200) resp.WriteHeader(200)
resp.Write([]byte(`{"success": false, "reason": "Successfully logged out"}`)) resp.Write([]byte(`{"success": false, "reason": "Successfully logged out"}`))
http.SetCookie(resp, c)
} }
func generateApikey(ctx context.Context, userInfo User) (User, error) { func generateApikey(ctx context.Context, userInfo User) (User, error) {
@@ -1471,6 +1452,8 @@ func handleUpdateUser(resp http.ResponseWriter, request *http.Request) {
return return
} }
// Should this role reflect the users' org access?
// When you change org -> change user role
if userInfo.Role != "admin" { if userInfo.Role != "admin" {
log.Printf("%s tried to update user %s", userInfo.Username, t.UserId) log.Printf("%s tried to update user %s", userInfo.Username, t.UserId)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -1486,6 +1469,21 @@ func handleUpdateUser(resp http.ResponseWriter, request *http.Request) {
return return
} }
orgFound := false
for _, item := range foundUser.Orgs {
if item == userInfo.ActiveOrg.Id {
orgFound = true
break
}
}
if !orgFound {
log.Printf("User %s is admin, but can't edit users outside their own org.", userInfo.Id)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Can't change users outside your org."}`)))
return
}
if t.Role != "admin" && t.Role != "user" { if t.Role != "admin" && t.Role != "user" {
log.Printf("%s tried and failed to update user %s", userInfo.Username, t.UserId) log.Printf("%s tried and failed to update user %s", userInfo.Username, t.UserId)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -1657,13 +1655,13 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
} }
ctx := context.Background() ctx := context.Background()
session, err := getSession(ctx, userInfo.Session) //session, err := getSession(ctx, userInfo.Session)
if err != nil { //if err != nil {
log.Printf("Session %#v doesn't exist: %s", session, err) // log.Printf("Session %#v doesn't exist: %s", session, err)
resp.WriteHeader(401) // resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "No session"}`)) // resp.Write([]byte(`{"success": false, "reason": "No session"}`))
return // return
} //}
// This is a long check to see if an inactive admin can access the site // This is a long check to see if an inactive admin can access the site
parsedAdmin := "false" parsedAdmin := "false"
@@ -1726,12 +1724,12 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
} }
//log.Printf("%s %s", session.Session, UserInfo.Session) //log.Printf("%s %s", session.Session, UserInfo.Session)
if session.Session != userInfo.Session { //if session.Session != userInfo.Session {
log.Printf("Session %s is not the same as %s for %s. %s", userInfo.Session, session.Session, userInfo.Username, err) // log.Printf("Session %s is not the same as %s for %s. %s", userInfo.Session, session.Session, userInfo.Username, err)
resp.WriteHeader(401) // resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": ""}`)) // resp.Write([]byte(`{"success": false, "reason": ""}`))
return // return
} //}
expiration := time.Now().Add(3600 * time.Second) expiration := time.Now().Add(3600 * time.Second)
http.SetCookie(resp, &http.Cookie{ http.SetCookie(resp, &http.Cookie{
@@ -2015,7 +2013,7 @@ func handlePasswordChange(resp http.ResponseWriter, request *http.Request) {
return return
} }
user, err := handleApiAuthentication(resp, request) userInfo, err := handleApiAuthentication(resp, request)
if err != nil { if err != nil {
log.Printf("Api authentication failed in set new workflowhandler: %s", err) log.Printf("Api authentication failed in set new workflowhandler: %s", err)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -2024,15 +2022,15 @@ func handlePasswordChange(resp http.ResponseWriter, request *http.Request) {
} }
curUserFound := false curUserFound := false
if t.Username != user.Username && user.Role != "admin" { if t.Username != userInfo.Username && userInfo.Role != "admin" {
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Admin required to change others' passwords"}`)) resp.Write([]byte(`{"success": false, "reason": "Admin required to change others' passwords"}`))
return return
} else if t.Username == user.Username { } else if t.Username == userInfo.Username {
curUserFound = true curUserFound = true
} }
if user.Role != "admin" { if userInfo.Role != "admin" {
if t.Newpassword != t.Newpassword2 { if t.Newpassword != t.Newpassword2 {
err := "Passwords don't match" err := "Passwords don't match"
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -2046,6 +2044,8 @@ func handlePasswordChange(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err))) resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
return return
} }
} else {
// Check ORG HERE?
} }
// Current password // Current password
@@ -2058,6 +2058,7 @@ func handlePasswordChange(resp http.ResponseWriter, request *http.Request) {
} }
ctx := context.Background() ctx := context.Background()
foundUser := User{}
if !curUserFound { if !curUserFound {
log.Printf("Have to find a different user") log.Printf("Have to find a different user")
q := datastore.NewQuery("Users").Filter("Username =", strings.ToLower(t.Username)) q := datastore.NewQuery("Users").Filter("Username =", strings.ToLower(t.Username))
@@ -2077,13 +2078,32 @@ func handlePasswordChange(resp http.ResponseWriter, request *http.Request) {
return return
} }
user = users[0] foundUser = users[0]
orgFound := false
if userInfo.ActiveOrg.Id == foundUser.ActiveOrg.Id {
orgFound = true
} else {
log.Printf("FoundUser: %#v", foundUser.Orgs)
for _, item := range foundUser.Orgs {
if item == userInfo.ActiveOrg.Id {
orgFound = true
break
}
}
}
if !orgFound {
log.Printf("User %s is admin, but can't change user's passowrd outside their own org.", userInfo.Id)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Can't change users outside your org."}`)))
return
}
} else { } else {
// Admins can re-generate others' passwords as well. // Admins can re-generate others' passwords as well.
if user.Role != "admin" { if userInfo.Role != "admin" {
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(t.Newpassword)) err = bcrypt.CompareHashAndPassword([]byte(userInfo.Password), []byte(t.Newpassword))
if err != nil { if err != nil {
log.Printf("Bad password for %s: %s", user.Username, err) log.Printf("Bad password for %s: %s", userInfo.Username, err)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`)) resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`))
return return
@@ -2091,18 +2111,25 @@ func handlePasswordChange(resp http.ResponseWriter, request *http.Request) {
} }
} }
if len(foundUser.Id) == 0 {
log.Printf("Something went wrong in password reset", err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
}
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(t.Newpassword), 8) hashedPassword, err := bcrypt.GenerateFromPassword([]byte(t.Newpassword), 8)
if err != nil { if err != nil {
log.Printf("New password failure for %s: %s", user.Username, err) log.Printf("New password failure for %s: %s", userInfo.Username, err)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`)) resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`))
return return
} }
user.Password = string(hashedPassword) userInfo.Password = string(hashedPassword)
err = setUser(ctx, &user) err = setUser(ctx, &foundUser)
if err != nil { if err != nil {
log.Printf("Error fixing password for user %s: %s", user.Username, err) log.Printf("Error fixing password for user %s: %s", userInfo.Username, err)
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`)) resp.Write([]byte(`{"success": false, "reason": "Username and/or password is incorrect"}`))
return return
@@ -2341,17 +2368,15 @@ func handleGetUsers(resp http.ResponseWriter, request *http.Request) {
// FIXME: Check by org. // FIXME: Check by org.
ctx := context.Background() ctx := context.Background()
var users []User org, err := getOrg(ctx, user.ActiveOrg.Id)
q := datastore.NewQuery("Users")
_, err = dbclient.GetAll(ctx, q, &users)
if err != nil { if err != nil {
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Can't get users"}`)) resp.Write([]byte(`{"success": false, "reason": "Failed getting org users"}`))
return return
} }
newUsers := []User{} newUsers := []User{}
for _, item := range users { for _, item := range org.Users {
if len(item.Username) == 0 { if len(item.Username) == 0 {
continue continue
} }
@@ -2458,19 +2483,10 @@ func handleLogin(resp http.ResponseWriter, request *http.Request) {
return return
} }
log.Printf("%s SUCCESSFULLY LOGGED IN with session %s", data.Username, Userdata.Session)
//if !Userdata.Verified {
// log.Printf("User %s is not verified", data.Username)
// resp.WriteHeader(403)
// resp.Write([]byte(`{"success": false, "reason": "Successful login, but your email address isn't verified. Check your mailbox."}`))
// return
//}
loginData := `{"success": true}`
// FIXME - have timeout here // FIXME - have timeout here
loginData := `{"success": true}`
if len(Userdata.Session) != 0 { if len(Userdata.Session) != 0 {
//log.Println("Nonexisting session") log.Println("User session exists - resetting")
expiration := time.Now().Add(3600 * time.Second) expiration := time.Now().Add(3600 * time.Second)
http.SetCookie(resp, &http.Cookie{ http.SetCookie(resp, &http.Cookie{
@@ -2490,20 +2506,36 @@ func handleLogin(resp http.ResponseWriter, request *http.Request) {
resp.WriteHeader(200) resp.WriteHeader(200)
resp.Write([]byte(loginData)) resp.Write([]byte(loginData))
return return
} else {
log.Printf("User session is empty - create one!")
sessionToken := uuid.NewV4().String()
expiration := time.Now().Add(3600 * time.Second)
http.SetCookie(resp, &http.Cookie{
Name: "session_token",
Value: sessionToken,
Expires: expiration,
})
// ADD TO DATABASE
err = SetSession(ctx, Userdata, sessionToken)
if err != nil {
log.Printf("Error adding session to database: %s", err)
}
Userdata.Session = sessionToken
err = setUser(ctx, &Userdata)
if err != nil {
log.Printf("Failed updating user when setting session: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
}
loginData = fmt.Sprintf(`{"success": true, "cookies": [{"key": "session_token", "value": "%s", "expiration": %d}]}`, sessionToken, expiration.Unix())
} }
sessionToken := uuid.NewV4() log.Printf("%s SUCCESSFULLY LOGGED IN with session %s", data.Username, Userdata.Session)
http.SetCookie(resp, &http.Cookie{
Name: "session_token",
Value: sessionToken.String(),
Expires: time.Now().Add(3600 * time.Second),
})
// ADD TO DATABASE
err = SetSession(ctx, Userdata, sessionToken.String())
if err != nil {
log.Printf("Error adding session to database: %s", err)
}
resp.WriteHeader(200) resp.WriteHeader(200)
resp.Write([]byte(loginData)) resp.Write([]byte(loginData))
@@ -2685,8 +2717,61 @@ func setEnvironment(ctx context.Context, data *Environment) error {
return nil return nil
} }
func fixUserOrg(ctx context.Context, user *User) *User {
found := false
for _, id := range user.Orgs {
if user.ActiveOrg.Id == id {
found = true
break
}
}
if !found {
user.Orgs = append(user.Orgs, user.ActiveOrg.Id)
}
log.Printf("Updating %d orgs for user %s", len(user.Orgs), user.Id)
// Might be vulnerable to timing attacks.
for _, orgId := range user.Orgs {
if len(orgId) == 0 {
continue
}
org, err := getOrg(ctx, orgId)
if err != nil {
log.Printf("Error getting org %s", orgId)
continue
}
orgIndex := 0
userFound := false
for index, orgUser := range org.Users {
if orgUser.Id == user.Id {
orgIndex = index
userFound = true
break
}
}
if userFound {
org.Users[orgIndex] = *user
} else {
org.Users = append(org.Users, *user)
}
err = setOrg(ctx, *org, orgId)
if err != nil {
log.Printf("Failed setting org %s", orgId)
}
}
return user
}
// ListBooks returns a list of books, ordered by title. // ListBooks returns a list of books, ordered by title.
func setUser(ctx context.Context, data *User) error { func setUser(ctx context.Context, data *User) error {
data = fixUserOrg(ctx, data)
// clear session_token and API_token for user // clear session_token and API_token for user
k := datastore.NameKey("Users", data.Id, nil) k := datastore.NameKey("Users", data.Id, nil)
if _, err := dbclient.Put(ctx, k, data); err != nil { if _, err := dbclient.Put(ctx, k, data); err != nil {
@@ -3481,6 +3566,7 @@ func handleNewHook(resp http.ResponseWriter, request *http.Request) {
}, },
}, },
Running: false, Running: false,
OrgId: user.ActiveOrg.Id,
} }
hook.Status = "running" hook.Status = "running"
@@ -7027,6 +7113,7 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) {
} }
// FIXME: Check if user is admin of this org // FIXME: Check if user is admin of this org
log.Printf("Checking org %s", org.Name)
userFound := false userFound := false
admin := false admin := false
for _, inneruser := range org.Users { for _, inneruser := range org.Users {
@@ -7061,7 +7148,7 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) {
// FIXME: Path // FIXME: Path
client := &http.Client{} client := &http.Client{}
apiPath := "/api/v1/cloud/sync" apiPath := "/api/v1/cloud/sync/setup"
if tmpData.Disable { if tmpData.Disable {
if !org.CloudSync { if !org.CloudSync {
log.Printf("Org %s isn't syncing. Can't stop.", org.Id) log.Printf("Org %s isn't syncing. Can't stop.", org.Id)
@@ -7072,9 +7159,9 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) {
log.Printf("Should disable sync for org %s", org.Id) log.Printf("Should disable sync for org %s", org.Id)
apiPath := "/api/v1/cloud/sync/stop" apiPath := "/api/v1/cloud/sync/stop"
syncUrl = fmt.Sprintf("%s%s", syncUrl, apiPath) syncPath := fmt.Sprintf("%s%s", syncUrl, apiPath)
err = handleStopCloudSync(syncUrl, *org) err = handleStopCloudSync(syncPath, *org)
if err != nil { if err != nil {
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err))) resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
@@ -7396,9 +7483,9 @@ func initHandlers() {
r.HandleFunc("/api/v1/users/logout", handleLogout).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/users/logout", handleLogout).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/users/register", handleRegister).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/users/register", handleRegister).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/users/checkusers", checkAdminLogin).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/checkusers", checkAdminLogin).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/users/getusers", handleGetUsers).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/users/getinfo", handleInfo).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/getinfo", handleInfo).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/users/getsettings", handleSettings).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/getsettings", handleSettings).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/users/getusers", handleGetUsers).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/users/updateuser", handleUpdateUser).Methods("PUT", "OPTIONS") r.HandleFunc("/api/v1/users/updateuser", handleUpdateUser).Methods("PUT", "OPTIONS")
r.HandleFunc("/api/v1/users/{user}", deleteUser).Methods("DELETE", "OPTIONS") r.HandleFunc("/api/v1/users/{user}", deleteUser).Methods("DELETE", "OPTIONS")
r.HandleFunc("/api/v1/users/passwordchange", handlePasswordChange).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/users/passwordchange", handlePasswordChange).Methods("POST", "OPTIONS")
@@ -7413,10 +7500,10 @@ func initHandlers() {
r.HandleFunc("/api/v1/getinfo", handleInfo).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/getinfo", handleInfo).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/getsettings", handleSettings).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/getsettings", handleSettings).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/generateapikey", handleApiGeneration).Methods("GET", "POST", "OPTIONS") r.HandleFunc("/api/v1/generateapikey", handleApiGeneration).Methods("GET", "POST", "OPTIONS")
r.HandleFunc("/api/v1/passwordchange", handlePasswordChange).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/getenvironments", handleGetEnvironments).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/getenvironments", handleGetEnvironments).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/setenvironments", handleSetEnvironments).Methods("PUT", "OPTIONS") r.HandleFunc("/api/v1/setenvironments", handleSetEnvironments).Methods("PUT", "OPTIONS")
r.HandleFunc("/api/v1/passwordchange", handlePasswordChange).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/docs", getDocList).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/docs", getDocList).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/docs/{key}", getDocs).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/docs/{key}", getDocs).Methods("GET", "OPTIONS")
@@ -7433,6 +7520,7 @@ func initHandlers() {
r.HandleFunc("/api/v1/workflows/queue/confirm", handleGetWorkflowqueueConfirm).Methods("POST") r.HandleFunc("/api/v1/workflows/queue/confirm", handleGetWorkflowqueueConfirm).Methods("POST")
// App specific // App specific
// From here down isnt checked for org specific
r.HandleFunc("/api/v1/apps/run_hotload", handleAppHotloadRequest).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/apps/run_hotload", handleAppHotloadRequest).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/apps/get_existing", loadSpecificApps).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/apps/get_existing", loadSpecificApps).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/apps/download_remote", loadSpecificApps).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/apps/download_remote", loadSpecificApps).Methods("POST", "OPTIONS")
@@ -7472,7 +7560,6 @@ func initHandlers() {
r.HandleFunc("/api/v1/workflows/{key}", deleteWorkflow).Methods("DELETE", "OPTIONS") r.HandleFunc("/api/v1/workflows/{key}", deleteWorkflow).Methods("DELETE", "OPTIONS")
// Triggers // Triggers
// Webhook redirect to the correct cloud function
r.HandleFunc("/api/v1/hooks/new", handleNewHook).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/hooks/new", handleNewHook).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/hooks/{key}", handleWebhookCallback).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/hooks/{key}", handleWebhookCallback).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/hooks/{key}/delete", handleDeleteHook).Methods("DELETE", "OPTIONS") r.HandleFunc("/api/v1/hooks/{key}/delete", handleDeleteHook).Methods("DELETE", "OPTIONS")
+36 -15
View File
@@ -105,6 +105,7 @@ type AppAuthenticationStorage struct {
Usage []AuthenticationUsage `json:"usage" datastore:"usage"` Usage []AuthenticationUsage `json:"usage" datastore:"usage"`
WorkflowCount int64 `json:"workflow_count" datastore:"workflow_count"` WorkflowCount int64 `json:"workflow_count" datastore:"workflow_count"`
NodeCount int64 `json:"node_count" datastore:"node_count"` NodeCount int64 `json:"node_count" datastore:"node_count"`
OrgId string `json:"org_id" datastore:"org_id"`
} }
type AuthenticationUsage struct { type AuthenticationUsage struct {
@@ -197,6 +198,7 @@ type WorkflowAppAction struct {
} }
// FIXME: Generate a callback authentication ID? // FIXME: Generate a callback authentication ID?
// FIXME: Add org check ..
type WorkflowExecution struct { type WorkflowExecution struct {
Type string `json:"type" datastore:"type"` Type string `json:"type" datastore:"type"`
Status string `json:"status" datastore:"status"` Status string `json:"status" datastore:"status"`
@@ -221,6 +223,7 @@ type WorkflowExecution struct {
Name string `json:"name" datastore:"name"` Name string `json:"name" datastore:"name"`
Value string `json:"value" datastore:"value,noindex"` Value string `json:"value" datastore:"value,noindex"`
} `json:"execution_variables,omitempty" datastore:"execution_variables,omitempty"` } `json:"execution_variables,omitempty" datastore:"execution_variables,omitempty"`
OrgId string `json:"org_id" datastore:"org_id"`
} }
// This is for the nodes in a workflow, NOT the app action itself. // This is for the nodes in a workflow, NOT the app action itself.
@@ -303,6 +306,7 @@ type Schedule struct {
Frequency string `json:"frequency" datastore:"frequency"` Frequency string `json:"frequency" datastore:"frequency"`
ExecutionArgument string `json:"execution_argument" datastore:"execution_argument,noindex"` ExecutionArgument string `json:"execution_argument" datastore:"execution_argument,noindex"`
Id string `json:"id" datastore:"id"` Id string `json:"id" datastore:"id"`
OrgId string `json:"org_id" datastore:"org_id"`
} }
type Workflow struct { type Workflow struct {
@@ -1047,6 +1051,7 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
extraInputs := 0 extraInputs := 0
for _, result := range workflowExecution.Results { for _, result := range workflowExecution.Results {
if result.Action.Name == "User Input" && result.Action.AppName == "User Input" { if result.Action.Name == "User Input" && result.Action.AppName == "User Input" {
log.Printf("Found User Input node - prepare cloud?")
extraInputs += 1 extraInputs += 1
} }
} }
@@ -1904,7 +1909,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
} }
} }
allAuths, err := getAllWorkflowAppAuth(ctx) allAuths, err := getAllWorkflowAppAuth(ctx, user.ActiveOrg.Id)
if userErr != nil { if userErr != nil {
log.Printf("Api authentication failed in get all apps: %s", userErr) log.Printf("Api authentication failed in get all apps: %s", userErr)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -2575,7 +2580,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
// FIXME: Authentication parameters // FIXME: Authentication parameters
if len(action.AuthenticationId) > 0 { if len(action.AuthenticationId) > 0 {
if len(allAuths) == 0 { if len(allAuths) == 0 {
allAuths, err = getAllWorkflowAppAuth(ctx) allAuths, err = getAllWorkflowAppAuth(ctx, workflow.ExecutingOrg.Id)
if err != nil { if err != nil {
log.Printf("Api authentication failed in get all app auth: %s", err) log.Printf("Api authentication failed in get all app auth: %s", err)
return WorkflowExecution{}, fmt.Sprintf("Api authentication failed in get all app auth: %s", err), err return WorkflowExecution{}, fmt.Sprintf("Api authentication failed in get all app auth: %s", err), err
@@ -2786,10 +2791,18 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
return WorkflowExecution{}, "Cloud not implemented yet", errors.New("Cloud not implemented yet") return WorkflowExecution{}, "Cloud not implemented yet", errors.New("Cloud not implemented yet")
} }
// What it needs to know:
// 1. Parameters
if len(workflowExecution.Workflow.Actions) == 1 { if len(workflowExecution.Workflow.Actions) == 1 {
log.Printf("Should execute directly with cloud instead of worker because only one action") log.Printf("Should execute directly with cloud instead of worker because only one action")
cloudExecuteAction(workflowExecution.ExecutionId, workflowExecution.Workflow.Actions[0], workflowExecution.ExecutionOrg)
return WorkflowExecution{}, "Cloud not implemented yet", errors.New("Cloud not implemented yet") //cloudExecuteAction(workflowExecution.ExecutionId, workflowExecution.Workflow.Actions[0], workflowExecution.ExecutionOrg, workflowExecution.Workflow.ID)
cloudExecuteAction(workflowExecution)
return WorkflowExecution{}, "Cloud not implemented yet (1)", errors.New("Cloud not implemented yet")
} else {
// If it's here, it should be controlled by Worker.
// If worker, should this backend be a proxy? I think so.
return WorkflowExecution{}, "Cloud not implemented yet (2)", errors.New("Cloud not implemented yet")
} }
} }
@@ -2802,22 +2815,30 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
} }
// This updates stuff locally from remote executions // This updates stuff locally from remote executions
func cloudExecuteAction(workflowExecutionId string, action Action, orgId string) error { func cloudExecuteAction(execution WorkflowExecution) error {
log.Printf("Executing action: %#v in execution ID %s", action, workflowExecutionId)
ctx := context.Background() ctx := context.Background()
org, err := getOrg(ctx, orgId) org, err := getOrg(ctx, execution.ExecutionOrg)
if err != nil { if err != nil {
return err return err
} }
type ExecutionStruct struct { type ExecutionStruct struct {
ID string `json:"id"` ExecutionId string `json:"execution_id" datastore:"execution_id"`
Action Action `json:"action"` Action Action `json:"action" datastore:"action"`
Authorization string `json:"authorization" datastore:"authorization"`
Results []ActionResult `json:"results" datastore:"results,noindex"`
ExecutionArgument string `json:"execution_argument" datastore:"execution_argument,noindex"`
WorkflowId string `json:"workflow_id" datastore:"workflow_id"`
ExecutionSource string `json:"execution_source" datastore:"execution_source"`
} }
data := ExecutionStruct{ data := ExecutionStruct{
ID: workflowExecutionId, ExecutionId: execution.ExecutionId,
Action: action, WorkflowId: execution.Workflow.ID,
Action: execution.Workflow.Actions[0],
Authorization: execution.Authorization,
} }
log.Printf("Executing action: %#v in execution ID %s", data.Action, data.ExecutionId)
b, err := json.Marshal(data) b, err := json.Marshal(data)
if err != nil { if err != nil {
@@ -3899,7 +3920,7 @@ func getAppAuthentication(resp http.ResponseWriter, request *http.Request) {
return return
} }
_, userErr := handleApiAuthentication(resp, request) user, userErr := handleApiAuthentication(resp, request)
if userErr != nil { if userErr != nil {
log.Printf("Api authentication failed in get all apps: %s", userErr) log.Printf("Api authentication failed in get all apps: %s", userErr)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -3915,7 +3936,7 @@ func getAppAuthentication(resp http.ResponseWriter, request *http.Request) {
// return // return
//} //}
ctx := context.Background() ctx := context.Background()
allAuths, err := getAllWorkflowAppAuth(ctx) allAuths, err := getAllWorkflowAppAuth(ctx, user.ActiveOrg.Id)
if err != nil { if err != nil {
log.Printf("Api authentication failed in get all app auth: %s", err) log.Printf("Api authentication failed in get all app auth: %s", err)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -5469,9 +5490,9 @@ func getAllWorkflowApps(ctx context.Context) ([]WorkflowApp, error) {
return allworkflowapps, nil return allworkflowapps, nil
} }
func getAllWorkflowAppAuth(ctx context.Context) ([]AppAuthenticationStorage, error) { func getAllWorkflowAppAuth(ctx context.Context, OrgId string) ([]AppAuthenticationStorage, error) {
var allworkflowapps []AppAuthenticationStorage var allworkflowapps []AppAuthenticationStorage
q := datastore.NewQuery("workflowappauth") q := datastore.NewQuery("workflowappauth").Filter("org_id = ", OrgId)
_, err := dbclient.GetAll(ctx, q, &allworkflowapps) _, err := dbclient.GetAll(ctx, q, &allworkflowapps)
if err != nil { if err != nil {
+1 -1
View File
@@ -1,7 +1,7 @@
version: '3' version: '3'
services: services:
frontend: frontend:
build: ./frontend #build: ./frontend
image: frikky/shuffle:frontend image: frikky/shuffle:frontend
container_name: shuffle-frontend container_name: shuffle-frontend
hostname: shuffle-frontend hostname: shuffle-frontend
+19 -18
View File
@@ -3,7 +3,7 @@ import React, { useState, useEffect } from 'react';
import { Route } from 'react-router'; import { Route } from 'react-router';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { CookiesProvider } from 'react-cookie'; import { CookiesProvider } from 'react-cookie';
import { useCookies } from 'react-cookie'; import { removeCookies, useCookies } from 'react-cookie';
import EditSchedule from "./views/EditSchedule"; import EditSchedule from "./views/EditSchedule";
import Schedules from "./views/Schedules"; import Schedules from "./views/Schedules";
@@ -93,23 +93,24 @@ const App = (message, props) => {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
}) })
.then(response => response.json()) .then(response => response.json())
.then(responseJson => { .then(responseJson => {
if (responseJson.success === true) { if (responseJson.success === true) {
//console.log(responseJson.success) //console.log(responseJson.success)
setUserData(responseJson) setUserData(responseJson)
setIsLoggedIn(true) setIsLoggedIn(true)
console.log("Cookies: ", cookies)
// Updating cookie every request // Updating cookie every request
for (var key in responseJson["cookies"]) { for (var key in responseJson["cookies"]) {
setCookie(responseJson["cookies"][key].key, responseJson["cookies"][key].value, { path: "/" }) setCookie(responseJson["cookies"][key].key, responseJson["cookies"][key].value, { path: "/" })
}
} }
setIsLoaded(true) }
}) setIsLoaded(true)
.catch(error => { })
setIsLoaded(true) .catch(error => {
}); setIsLoaded(true)
});
} }
// Dumb for content load (per now), but good for making the site not suddenly reload parts (ajax thingies) // Dumb for content load (per now), but good for making the site not suddenly reload parts (ajax thingies)
@@ -124,7 +125,7 @@ const App = (message, props) => {
<Route exact path="/home" render={props => <LandingPageNew isLoaded={isLoaded} {...props} />} /> <Route exact path="/home" render={props => <LandingPageNew isLoaded={isLoaded} {...props} />} />
</div> : </div> :
<div style={{ backgroundColor: "#1F2023", color: "rgba(255, 255, 255, 0.65)", minHeight: "100vh" }}> <div style={{ backgroundColor: "#1F2023", color: "rgba(255, 255, 255, 0.65)", minHeight: "100vh" }}>
<Header removeCookie={removeCookie} isLoaded={isLoaded} globalUrl={globalUrl} setIsLoggedIn={setIsLoggedIn} isLoggedIn={isLoggedIn} userdata={userdata} {...props} /> <Header cookies={cookies} removeCookie={removeCookie} isLoaded={isLoaded} globalUrl={globalUrl} setIsLoggedIn={setIsLoggedIn} isLoggedIn={isLoggedIn} userdata={userdata} {...props} />
<Route exact path="/oauth2" render={props => <Oauth2 isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} /> <Route exact path="/oauth2" render={props => <Oauth2 isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} />
<Route exact path="/contact" render={props => <Contact isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} /> <Route exact path="/contact" render={props => <Contact isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} />
<Route exact path="/login" render={props => <LoginPage isLoggedIn={isLoggedIn} setIsLoggedIn={setIsLoggedIn} register={true} isLoaded={isLoaded} globalUrl={globalUrl} setCookie={setCookie} cookies={cookies} {...props} />} /> <Route exact path="/login" render={props => <LoginPage isLoggedIn={isLoggedIn} setIsLoggedIn={setIsLoggedIn} register={true} isLoaded={isLoaded} globalUrl={globalUrl} setCookie={setCookie} cookies={cookies} {...props} />} />
@@ -140,7 +141,7 @@ const App = (message, props) => {
<Route exact path="/apps/new" render={props => <AppCreator isLoaded={isLoaded} isLoggedIn={isLoggedIn} globalUrl={globalUrl} {...props} />} /> <Route exact path="/apps/new" render={props => <AppCreator isLoaded={isLoaded} isLoggedIn={isLoggedIn} globalUrl={globalUrl} {...props} />} />
<Route exact path="/apps/edit/:appid" render={props => <AppCreator isLoaded={isLoaded} isLoggedIn={isLoggedIn} globalUrl={globalUrl} {...props} />} /> <Route exact path="/apps/edit/:appid" render={props => <AppCreator isLoaded={isLoaded} isLoggedIn={isLoggedIn} globalUrl={globalUrl} {...props} />} />
<Route exact path="/schedules/:key" render={props => <EditSchedule globalUrl={globalUrl} {...props} />} /> <Route exact path="/schedules/:key" render={props => <EditSchedule globalUrl={globalUrl} {...props} />} />
<Route exact path="/workflows" render={props => <Workflows isLoaded={isLoaded} isLoggedIn={isLoggedIn} globalUrl={globalUrl} cookies={cookies} {...props} />} /> <Route exact path="/workflows" render={props => <Workflows cookies={cookies} removeCookie={removeCookie} isLoaded={isLoaded} isLoggedIn={isLoggedIn} globalUrl={globalUrl} cookies={cookies} {...props} />} />
<Route exact path="/workflows/:key" render={props => <AngularWorkflow userdata={userdata} globalUrl={globalUrl} isLoaded={isLoaded} isLoggedIn={isLoggedIn} {...props} />} /> <Route exact path="/workflows/:key" render={props => <AngularWorkflow userdata={userdata} globalUrl={globalUrl} isLoaded={isLoaded} isLoggedIn={isLoggedIn} {...props} />} />
<Route exact path="/docs/:key" render={props => <Docs isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} /> <Route exact path="/docs/:key" render={props => <Docs isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} />
<Route exact path="/docs" render={props => { window.location.pathname = "/docs/about" }} /> <Route exact path="/docs" render={props => { window.location.pathname = "/docs/about" }} />
+23 -18
View File
@@ -19,7 +19,7 @@ const hoverColor = "#f85a3e"
const hoverOutColor = "#e8eaf6" const hoverOutColor = "#e8eaf6"
const Header = props => { const Header = props => {
const { globalUrl, isLoggedIn, removeCookie, homePage, isLoaded, userdata } = props; const { globalUrl, isLoggedIn, removeCookie, homePage, isLoaded, userdata, cookies } = props;
const theme = useTheme(); const theme = useTheme();
const [HomeHoverColor, setHomeHoverColor] = useState(hoverOutColor); const [HomeHoverColor, setHomeHoverColor] = useState(hoverOutColor);
@@ -35,26 +35,31 @@ const Header = props => {
// DEBUG HERE // DEBUG HERE
const handleClickLogout = () => { const handleClickLogout = () => {
console.log("SHOULD LOG OUT") console.log("COOKIES: ", cookies, "Remover: ", removeCookie)
console.log(isLoggedIn)
// Don't really care about the logout // Don't really care about the logout
fetch(globalUrl+"/api/v1/logout", { fetch(globalUrl+"/api/v1/logout", {
credentials: "include", credentials: "include",
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
}) })
.then(() => { .then(() => {
// Log out anyway // Log out anyway
removeCookie("session_token", {path: "/"}) //cookies.remove("session_token")
//window.location.pathname = "/" //window.location.pathname = "/"
}) console.log("Should've logged out")
removeCookie("session_token", {path: "/"})
removeCookie("session_token", {path: "/workflows"})
window.location.reload()
})
.catch(error => { .catch(error => {
console.log(error) console.log("Error in logout: ", error)
}); removeCookie("session_token", {path: "/"})
} window.location.reload()
//removeCookie("session_token", {path: "/"})
})
}
// Rofl this is weird // Rofl this is weird
const handleDocsHover = () => { const handleDocsHover = () => {
+2 -2
View File
@@ -1136,9 +1136,9 @@ const Admin = (props) => {
}} }}
> >
Edit user Edit user
</Button> </Button>
</ListItemText> </ListItemText>
</ListItem> </ListItem>
) )
})} })}
</List> </List>
File diff suppressed because one or more lines are too long
-4
View File
@@ -160,10 +160,6 @@ const LoginDialog = props => {
//var loginChange = register ? (<div><p onClick={setLoginCheck(false)}>Want to register? Click here.</p></div>) : (<div><p onClick={setLoginCheck(true)}>Go back to login? Click here.</p></div>); //var loginChange = register ? (<div><p onClick={setLoginCheck(false)}>Want to register? Click here.</p></div>) : (<div><p onClick={setLoginCheck(true)}>Go back to login? Click here.</p></div>);
var formtitle = register ? <div>Login</div> : <div>Register</div> var formtitle = register ? <div>Login</div> : <div>Register</div>
// <DialogTitle>{formtitle}</DialogTitle>
console.log("THEME: ", theme.palette.surfaceColor)
const basedata = const basedata =
<div style={bodyDivStyle}> <div style={bodyDivStyle}>
<Paper style={{ <Paper style={{
+34 -6
View File
@@ -33,7 +33,6 @@ import {Link} from 'react-router-dom';
import { useAlert } from "react-alert"; import { useAlert } from "react-alert";
import ChipInput from 'material-ui-chip-input' import ChipInput from 'material-ui-chip-input'
import Dialog from '@material-ui/core/Dialog'; import Dialog from '@material-ui/core/Dialog';
import DialogTitle from '@material-ui/core/DialogTitle'; import DialogTitle from '@material-ui/core/DialogTitle';
import DialogActions from '@material-ui/core/DialogActions'; import DialogActions from '@material-ui/core/DialogActions';
@@ -44,7 +43,7 @@ const inputColor = "#383B40"
const surfaceColor = "#27292D" const surfaceColor = "#27292D"
const Workflows = (props) => { const Workflows = (props) => {
const { globalUrl, isLoggedIn, isLoaded, } = props; const { globalUrl, isLoggedIn, isLoaded, removeCookie, cookies} = props;
document.title = "Shuffle - Workflows" document.title = "Shuffle - Workflows"
const alert = useAlert() const alert = useAlert()
@@ -83,6 +82,31 @@ const Workflows = (props) => {
} }
}) })
// DEBUG HERE
const handleClickLogout = () => {
//console.log("Cookies: ", cookies)
//console.log("SHOULD LOG OUT")
//console.log(isLoggedIn)
// Don't really care about the logout
//fetch(globalUrl+"/api/v1/logout", {
// credentials: "include",
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
//})
//.then(() => {
// // Log out anyway
// removeCookie("session_token", {path: "/"})
// //window.location = "/login"
//})
//.catch(error => {
// console.log(error)
// removeCookie("session_token", {path: "/"})
//});
}
const deleteModal = deleteModalOpen ? const deleteModal = deleteModalOpen ?
<Dialog <Dialog
open={deleteModalOpen} open={deleteModalOpen}
@@ -124,13 +148,13 @@ const Workflows = (props) => {
const getAvailableWorkflows = () => { const getAvailableWorkflows = () => {
fetch(globalUrl+"/api/v1/workflows", { fetch(globalUrl+"/api/v1/workflows", {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json', 'Accept': 'application/json',
}, },
credentials: "include", credentials: "include",
}) })
.then((response) => { .then((response) => {
if (response.status !== 200) { if (response.status !== 200) {
console.log("Status not 200 for workflows :O!") console.log("Status not 200 for workflows :O!")
@@ -149,7 +173,7 @@ const Workflows = (props) => {
if (isLoggedIn) { if (isLoggedIn) {
alert.error("An error occurred while loading workflows") alert.error("An error occurred while loading workflows")
} else { } else {
window.location = "/login" handleClickLogout()
} }
return return
@@ -586,6 +610,10 @@ const Workflows = (props) => {
return null return null
} }
if (data.workflow.actions === null || data.workflow.actions === undefined) {
return null
}
var actions = data.workflow.actions.length var actions = data.workflow.actions.length
if (data.results !== null) { if (data.results !== null) {
var results = data.results.length var results = data.results.length