本文整理匯總了Golang中github.com/hoysoft/JexGO/sessions.Session類的典型用法代碼示例。如果您正苦於以下問題:Golang Session類的具體用法?Golang Session怎麽用?Golang Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Session類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoginRequired
// LoginRequired verifies that the current user is authenticated. Any routes that
// require a login should have this handler placed in the flow. If the user is not
// authenticated, they will be redirected to /login with the "next" get parameter
// set to the attempted URL.
func LoginRequired(s sessions.Session, r render.Render, user IUser, req *http.Request) {
if user.IsAuthenticated() == false {
s.Delete(SessionKey)
path := fmt.Sprintf("%s?%s=%s", RedirectUrl, RedirectParam, req.URL.Path)
r.Redirect(path, 302)
}
}
示例2: unmarshallToken
func unmarshallToken(s sessions.Session) (t *token) {
if s.Get(keyToken) == nil {
return
}
data := s.Get(keyToken).([]byte)
var tk token
json.Unmarshal(data, &tk)
return &tk
}
示例3: loginHandle
func loginHandle(f *Config, s sessions.Session, w http.ResponseWriter, r *http.Request) {
next := extractPath(r.URL.Query().Get(RedirectParam))
s.Set("_RedirectURL", next)
// if len(f.ClientID) > 0 && len(f.ClientSecret) > 0 {
// http.Redirect(w, r, f.authCodeURL(), 302)
// }else {
path := fmt.Sprintf("%s?redirect_uri=%s", f.Endpoint.LoginURL, f.RedirectURL)
http.Redirect(w, r, path, 302)
// }
}
示例4: logoutHandle
func logoutHandle(f *Config, c martini.Context, s sessions.Session, w http.ResponseWriter, r *http.Request) {
s.Delete(keyToken)
path := fmt.Sprintf("%s?client_id=%s&client_secret=%s", f.Endpoint.LogoutURL, f.ClientID, f.ClientSecret)
utils.HttpGetString(path)
// fmt.Println("oauth logout result:",string(str))
f.ClientID = ""
f.ClientSecret = ""
c.Invoke(Logout)
http.Redirect(w, r, "/", 302)
}
示例5: UpdateUser
// UpdateUser updates the User object stored in the session. This is useful incase a change
// is made to the user model that needs to persist across requests.
func UpdateUser(s sessions.Session, user IUser) error {
s.Set(SessionKey, user.UniqueId())
return nil
}
示例6: Logout
// Logout will clear out the session and call the Logout() user function.
func Logout(s sessions.Session, user IUser) {
user.Logout()
s.Delete(SessionKey)
}
示例7: callbackhandle
func callbackhandle(f *Config, c martini.Context, s sessions.Session, w http.ResponseWriter, r *http.Request) {
rurl, _ := s.Get("_RedirectURL").(string)
rurl = extractPath(rurl)
if len(r.URL.Query().Get("code")) > 0 {
//獲取token
tk, error := f.authTokenURL(r.URL.Query().Get("code"))
if error == nil && tk.Valid() {
val, _ := json.Marshal(tk)
s.Set(keyToken, val)
fmt.Println("登陸成功")
s.AddFlash("登陸成功")
c.Invoke(oAuthUserLoginCallback)
if len(rurl) == 0 {
rurl = "/"
}
fmt.Println("rul:", rurl)
http.Redirect(w, r, rurl, 302)
return
} else {
s.AddFlash("登陸失敗")
http.Redirect(w, r, PathError, 302)
return
}
}
if len(r.URL.Query().Get("client_id")) > 0 {
f.ClientID = r.URL.Query().Get("client_id")
f.ClientSecret = r.URL.Query().Get("client_secret")
http.Redirect(w, r, f.authCodeURL(), 302)
return
}
// fmt.Println("call:",r)
// if (len(r.URL.Query().Get("code"))>0) {
// fmt.Println("callFUN:q token")
// rurl,_:= s.Get("_RedirectURL").(string)
// //獲取token
// tk, error := f.authTokenURL(r.URL.Query().Get("code"))
// if error==nil && tk.Valid() {
// val, _ := json.Marshal(tk)
// s.Set(keyToken, val)
// s.AddFlash("success","登陸成功")
// c.Invoke(oAuthUserLogin)
//
//
// http.RedirectHandler(rurl, 302)
// return
// }else{
// s.AddFlash("warning","登陸失敗")
// http.Redirect(w, r, PathError, 302)
// return
// }
// }else{
// fmt.Println("callFUN:1111")
// //獲取code
// if len(r.URL.Query().Get("client_id"))>0 {
// fmt.Println("callFUN:q code")
// f.ClientID = r.URL.Query().Get("client_id")
// f.ClientSecret = r.URL.Query().Get("client_secret")
// http.Redirect(w, r, f.authCodeURL(), 302)
// return
// }
// http.Redirect(w, r, "/", 302)
// }
// fmt.Println("callFUN:sppp")
}