• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang sessions.Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
	}
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:11,代码来源:sessionAuth.go


示例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
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:9,代码来源:token.go


示例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)
	//	}
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:10,代码来源:oauth2.go


示例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)
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:10,代码来源:oauth2.go


示例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
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:6,代码来源:sessionAuth.go


示例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)
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:5,代码来源:sessionAuth.go


示例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")
}
开发者ID:hoysoft,项目名称:JexGO,代码行数:66,代码来源:oauth2.go



注:本文中的github.com/hoysoft/JexGO/sessions.Session类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang tail.TailFile函数代码示例发布时间:2022-05-28
下一篇:
Golang gopass.GetPasswdMasked函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap