func (c Auth) Logout() revel.Result { bucket = services.GetBucket() _ = bucket.Delete(fmt.Sprintf("authtoken-%s", c.Session["authtoken"])) delete(c.Session, "authtoken") delete(c.Session, "userid") delete(c.Session, "userimg") delete(c.Session, "username") url := fmt.Sprintf("https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=%s", rootUrl) return c.Redirect(url) }
func (c Home) Index() revel.Result { userid := c.Session["userid"] if userid != "" { bucket := services.GetBucket() r, err := bucket.GetRaw(fmt.Sprintf("authtoken-%s", userid)) if err == nil && len(r) > 0 { return c.Redirect("/tasks") } } return c.Render() }
package controllers import ( "fmt" "github.com/revel/revel" "github.com/xeb/flowdle/app/services" ) var ( bucket = services.GetBucket() rootUrl = "http://localhost:9000" // todo: auto identify? ) type Auth struct { *revel.Controller } func (c Auth) Index() revel.Result { tokenCache := services.NewOAuthCache(c.Session, bucket) r, _ := services.TryOAuth(*tokenCache, "") if r.Success == false { return c.Redirect(r.AuthURL) } c.Session["username"] = r.Account.Name return c.Redirect("/tasks") } func (c Auth) Callback() revel.Result { tokenCache := services.NewOAuthCache(c.Session, bucket)