示例#1
0
文件: auth.go 项目: xeb/flowdle
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")
}
示例#2
0
文件: auth.go 项目: xeb/flowdle
func (c Auth) Callback() revel.Result {
	tokenCache := services.NewOAuthCache(c.Session, bucket)
	code := c.Params.Get("code")
	r, err := services.TryOAuth(tokenCache, code)
	if err != nil {
		return c.RenderText(fmt.Sprintf("%s", err))
	}

	c.Session["userid"] = r.Account.Id
	c.Session["username"] = r.Account.Name
	c.Session["userimg"] = r.Account.Picture

	if r.Success {
		return c.Redirect("/tasks")
	}

	c.Response.Status = 401
	return c.RenderText("Unauthorized")
}