Example #1
0
// For login authentication from picasa.
// TODO: Add error handling.
func AuthHandler(c http.ResponseWriter, r *http.Request) {
	// Get the token supplied in the URL.
	picasaLen := len("token=")
	url, _ := http.URLUnescape(r.URL.RawQuery)
	token := url[picasaLen:]
	fmt.Println(token, r.URL.RawQuery)

	// Try to upgrade the token to a multi-use one. See
	// http://code.google.com/apis/accounts/docs/AuthSub.html
	req := picasa.NewRequest("https://www.google.com/accounts/accounts/AuthSubSessionToken", token, "GET")
	resp, e := picasa.Send(req)

	// Get the upgraded token value
	body, e := ioutil.ReadAll(resp.Body)
	if e != nil {
		fmt.Println(e)
	}
	resp.Body.Close()
	if len(body) <= picasaLen {
		dlog.Println("Invalid or missing token! Response received was:", body)
		template.Error500(c, r, nil)
	}
	upgradedToken := body[picasaLen:]
	fmt.Println("Upgraded Token: ", string(upgradedToken))

	// Finally, save the upgraded token in the server-side session.
	u, _ := user.Get(c, r)
	u.Set("picasa-authsub-token", string(upgradedToken))
	http.Redirect(c, r, "/photos/upload", http.StatusFound)
}
Example #2
0
func UploaderHandler(c http.ResponseWriter, r *http.Request) {
	u, _ := user.Get(c, r)
	token := u.Get("picasa-authsub-token")
	fmt.Println("Host:", r.Host)
	albums := GetAlbums()

	data := new(UploaderData)
	data.Albums = albums
	data.PicasaAuthenticated = (token != "")
	// TODO: Make photos use the new login system.

	tmpl.Render(c, r, "Upload Photos", "uploader", data)
}