本文整理匯總了Golang中github.com/mongolar/mongolar/wrapper.Wrapper.SetSessionValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Wrapper.SetSessionValue方法的具體用法?Golang Wrapper.SetSessionValue怎麽用?Golang Wrapper.SetSessionValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mongolar/mongolar/wrapper.Wrapper
的用法示例。
在下文中一共展示了Wrapper.SetSessionValue方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Callback
func (lo *LoginMap) Callback(w *wrapper.Wrapper) {
oauthlogins := make(map[string]map[string]string)
w.SiteConfig.RawConfig.MarshalKey("OAuthLogins", &oauthlogins)
loginurls := make(map[string]string)
w.SiteConfig.RawConfig.MarshalKey("LoginURLs", &loginurls)
if _, ok := oauthlogins[w.APIParams[0]]; ok {
if _, ok := lo.Logins[w.APIParams[0]]; ok {
s := w.Request.FormValue("state")
sc := oauthlogins[w.APIParams[0]]
login := lo.Logins[w.APIParams[0]]
if lo.State != s {
errmessage := fmt.Sprintf("Invalid oauth state, expected %s, got %s", lo.State, s)
w.SiteConfig.Logger.Error(errmessage)
http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
return
}
login.SetConfig(sc, "", "")
code := w.Request.FormValue("code")
token, err := login.GetToken(code)
if err != nil {
errmessage := fmt.Sprintf("Exchange() failed with %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
return
}
u := login.GetUser()
err = u.Set(w)
if err != nil {
errmessage := fmt.Sprintf("Unable to set user: %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
return
}
err = w.SetSessionValue("user_id", u.MongoId)
if err != nil {
errmessage := fmt.Sprintf("Unable to set user id on session: %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
return
}
err = w.SetSessionValue("token", token)
if err != nil {
errmessage := fmt.Sprintf("Unable to set token on session: %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
return
}
http.Redirect(w.Writer, w.Request, loginurls["success"], 301)
return
}
}
http.Error(w.Writer, "Forbidden", 403)
return
}