コード例 #1
0
func SigninWithGoogle(w http.ResponseWriter, r *http.Request) {
	if !helpers.SignedIn(r) {
		c := appengine.NewContext(r)

		// Set up a Transport using the config.
		transport := &oauth.Transport{Config: config, Transport: &urlfetch.Transport{Context: c}}

		// get the access token
		token, err := authorize(w, r, transport)
		if err != nil {
			c.Debugf("%q", err)
		}

		// store token to authenticate
		transport.Token = token

		if currentUser, _ := getCurrentUser(r, transport); currentUser != nil {
			//save the session
			helpers.SignIn(w, fmt.Sprintf("%d", currentUser.Id))
		}
	}

	// redirect to home
	http.Redirect(w, r, "/", http.StatusFound)
	return
}
コード例 #2
0
func Signin(w http.ResponseWriter, r *http.Request) {
	if !helpers.SignedIn(r) {
		renderSigninPage(w)
	} else {
		// redirect to home
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
}