Beispiel #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)
}
Beispiel #2
0
func (m *Module) IsRunning() bool {
	//dlog.Printf("%#v %#v %#v\n", m, m.MainProcess, m.SyncProcess)
	waitmsg, err := os.Wait(m.MainProcess.Pid, os.WNOHANG|os.WUNTRACED)
	if err != nil {
		// TODO: When would this happen?
		dlog.Println("Unable to get process wait status:", err)
	}
	//dlog.Printf("%#v\n", waitmsg)
	// If status is not available, the pid is 0.
	if waitmsg.Pid == 0 {
		return true
	}
	if waitmsg.WaitStatus.Exited() {
		modules[m.Name] = nil, false
		return false
	}
	return true
}