Ejemplo n.º 1
0
// Enumerate the total number of users on the system
func yourFilesHandler(w http.ResponseWriter, r *http.Request) {
	session, err := store.Get(r, "session-name")
	token := session.Values["token"].(string)

	ac, err := aerofsapi.NewAuthClient(appConfig, "", "", []string{})
	a, _ := aerofsapi.NewClient(token, ac.AeroUrl)

	logger.Print("Attempting to parse user files page")
	t, err := template.ParseFiles("templates/userFiles.tmpl")
	if err != nil {
		logger.Println("Unable to retrieve template file")
		http.Error(w, err.Error(), 500)
		return
	}

	// Retrieve children of root folder
	folder, err := sdk.NewFolderClient(a, "root", []string{})
	if err != nil {
		logger.Println("Unable to retrieve file client for file.")
		http.Error(w, err.Error(), 500)
		return
	}

	folder.LoadPath()
	folder.LoadChildren()
	logger.Print(folder.Desc.ChildList.Files)
	logger.Print(folder.Desc.ChildList.Folders)
	t.Execute(w, folder.Desc)
	session.Save(r, w)
}
Ejemplo n.º 2
0
// Retrieve the root folder for a given user
func TestGetFolder(t *testing.T) {
	c, _ := api.NewClient(UserToken, "share.syncfs.com")
	f, e := NewFolderClient(c, "root", []string{"path", "children"})
	if e != nil {
		t.Fatalf("Unable to retrieve a FolderClient : %s", e)
	}

	f.LoadChildren()
	f.LoadMetadata()
	t.Log(*f)
}
Ejemplo n.º 3
0
// Retrieve a list of backend users
func TestListUsers(t *testing.T) {
	c, _ := api.NewClient(AdminToken, "share.syncfs.com")
	u, e := ListUsers(c, 1000)
	if e != nil {
		t.Fatalf("Unable to retrieve a list of users : %s", e)
	}
	if u != nil {
		t.Logf("There are %d users", len(*u))
		t.Log(*u)
	}
}
Ejemplo n.º 4
0
// Remove all of test-generated users
// Note that users with <email>@aerofs.com are persisted and not removed
func rmUsers() error {
	c, _ := api.NewClient(AdminToken, "share.syncfs.com")
	users, e := ListUsers(c, 1000)
	if e != nil {
		return e
	}

	for _, user := range *users {
		uClient := UserClient{c, user}
		if !strings.Contains(uClient.Desc.Email, "aerofs.com") {
			err := uClient.Delete()
			if err != nil {
				fmt.Printf("Unable to remove users")
				return err
			}
		}
	}
	return nil
}
Ejemplo n.º 5
0
// Enumerate the users devices
func yourDevicesHandler(w http.ResponseWriter, r *http.Request) {
	session, err := store.Get(r, "session-name")
	token := session.Values["token"].(string)

	ac, err := aerofsapi.NewAuthClient(appConfig, "", "", []string{})
	a, _ := aerofsapi.NewClient(token, ac.AeroUrl)
	devices, _ := sdk.ListDevices(a, session.Values["email"].(string))
	logger.Print(devices)

	t, err := template.ParseFiles("templates/userDevices.tmpl")
	logger.Print("Attempting to parse user devices page")
	if err != nil {
		logger.Println("Unable to retrieve template file")
		http.Error(w, err.Error(), 500)
		return
	}
	t.Execute(w, devices)
	session.Save(r, w)
}
Ejemplo n.º 6
0
// Update an already existing user
func TestUpdateUser(t *testing.T) {
	// Create new user
	c, _ := api.NewClient(AdminToken, "share.syncfs.com")
	email := fmt.Sprintf("*****@*****.**", rand.Intn(10000))
	firstName := "Melkor"
	lastName := "Bauglir"
	u, e := CreateUserClient(c, email, firstName, lastName)
	if e != nil {
		t.Fatalf("Unable to create new user : %s", e)
	}

	// Update created user
	t.Log(*u)
	e = u.Update("Eru", "Iluvatar")
	if e != nil {
		t.Log(e)
		t.Fatalf("Unable to update user")
	} else {
		t.Logf("Successfully updated user")
		t.Log(*u)
	}

}
Ejemplo n.º 7
0
// Create a new user
func TestCreateUser(t *testing.T) {
	t.Logf("Creating new user")
	c, _ := api.NewClient(AdminToken, "share.syncfs.com")

	t.Logf("Creating a new user")
	rand.Seed(int64(os.Getpid()))
	email := fmt.Sprintf("*****@*****.**", rand.Intn(100))
	firstName := "Melkor"
	lastName := "Bauglir"
	u, e := CreateUserClient(c, email, firstName, lastName)

	if e != nil {
		t.Log(e)
		t.Fatalf("Unable to create new user")
	} else if u.Desc.Email == email && u.Desc.FirstName == firstName && u.Desc.LastName == lastName {
		t.Logf("Successfully created a new user")
		t.Log(*u)
	} else {
		t.Fatal("User created with incorrect fields")
		if u != nil {
			t.Fatal(*u)
		}
	}
}