func (m *SessionHandler) Call(e *httpapp.Env) *httpapp.Response { session, err := m.GetSession(e) if err != nil { session = sessions.NewSession(m.State.Generate()) } e.Set("session", session) resp := m.App.Call(e) m.Finalize(session, resp) return resp }
func (a *GoogleOAuthHandler) checkSession(e *httpapp.Env) *httpapp.Response { session := e.Get("session").(*sessions.Session) if _, ok := session.Data["user"]; !ok { session.Data["return_to"] = e.Request.URL.Path url := a.OauthConfig.AuthCodeURL("") resp := httpapp.NewResponse(http.StatusFound) resp.Headers.Add("Location", url) return resp } else { return a.App.Call(e) } }
func (a *GoogleOAuthHandler) handleOAuth2Callback(e *httpapp.Env) *httpapp.Response { t := &oauth.Transport{Config: a.OauthConfig} t.Exchange(e.Request.FormValue("code")) base_user_info := a.getBaseUserInfo(t) ext_user_info := a.getExtendedUserInfo(t, base_user_info) user_info := auth.NewGoogleUser( base_user_info.Id, base_user_info.Email, ext_user_info.FullName, ) session := e.Get("session").(*sessions.Session) session.Data["user"] = user_info resp := httpapp.NewResponse(http.StatusFound) resp.Headers.Add("Location", session.Data["return_to"].(string)) return resp }
func (c *ContentController) commitChanges(f *model.VersionedFile, e *httpapp.Env) { session := e.Get("session").(*sessions.Session) user := session.Data["user"].(*auth.GoogleUser) out := f.CommitFor(user.AuthorString()) log.Print(out) }