Example #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)
}
Example #2
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)
}
Example #3
0
// Receive a Token after user accepts permissions
// Redirect to the devices page
func tokenization(rw http.ResponseWriter, req *http.Request) {

	// Retrieve session-id so we can store corresponding token with it
	session, err := store.Get(req, "session-name")
	ac, err := aerofsapi.NewAuthClient(appConfig,
		"http://"+hostName+"/tokenization", "uniqueState", []string{})

	// disregard state
	code := req.URL.Query().Get("code")
	token, _, err := ac.GetAccessToken(code)
	logger.Print("New activated user ...")
	logger.Printf("\tEmail : %s | Code : %s | Token : %s",
		session.Values["email"], code, token)
	if err != nil {
		logger.Println("Unable to get correct access token")
	}

	session.Values["token"] = token
	session.Save(req, rw)
	http.Redirect(rw, req, "http://"+hostName+"/devices", 301)
}
Example #4
0
// Handler for when a user submits their email
// The user is redirected to the AeroFS Appliance, where they must grant the App
// requested permissions
func loginSubmitHandler(w http.ResponseWriter, r *http.Request) {
	// Get new session
	session, _ := store.Get(r, "session-name")

	// Assumes a valid email was given
	r.ParseForm()
	session.Values["email"] = r.Form.Get("email")

	// Redirect User to AeroFS Appliance to retrieve Authorization Code
	ac, err := aerofsapi.NewAuthClient(appConfig,
		"http://"+hostName+"/tokenization",
		"uniqueState", []string{"files.read", "files.write", "user.read", "user.write", "user.password"})
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	aeroUrl := ac.GetAuthorizationUrl()
	logger.Printf("Sending user %s to the AeroFS Appliance at %s", session.Values["email"], aeroUrl)
	session.Save(r, w)
	http.Redirect(w, r, aeroUrl, 301)
}