本文整理汇总了Golang中github.com/macaron-contrib/session.Store类的典型用法代码示例。如果您正苦于以下问题:Golang Store类的具体用法?Golang Store怎么用?Golang Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SignedInId
// SignedInId returns the id of signed in user.
func SignedInId(header http.Header, sess session.Store) int64 {
if !models.HasEngine {
return 0
}
if setting.Service.EnableReverseProxyAuth {
webAuthUser := header.Get(setting.ReverseProxyAuthUser)
if len(webAuthUser) > 0 {
u, err := models.GetUserByName(webAuthUser)
if err != nil {
if err != models.ErrUserNotExist {
log.Error(4, "GetUserByName: %v", err)
}
return 0
}
return u.Id
}
}
uid := sess.Get("uid")
if uid == nil {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserById(id); err != nil {
if err != models.ErrUserNotExist {
log.Error(4, "GetUserById: %v", err)
}
return 0
}
return id
}
return 0
}
开发者ID:ericcapricorn,项目名称:gogs,代码行数:35,代码来源:auth.go
示例2: unmarshallToken
func unmarshallToken(s session.Store) (t *token) {
if s.Get(keyToken) == nil {
return
}
data := s.Get(keyToken).([]byte)
var tk oauth2.Token
json.Unmarshal(data, &tk)
return &token{tk}
}
开发者ID:gorelease,项目名称:oauth2,代码行数:9,代码来源:oauth2.go
示例3: unmarshallToken
func unmarshallToken(s session.Store) (t *Token) {
if s.Get(KEY_TOKEN) == nil {
return
}
data := s.Get(KEY_TOKEN).([]byte)
var tk Token
json.Unmarshal(data, &tk)
return &tk
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:9,代码来源:social.go
示例4: login
func login(f *oauth2.Config, s session.Store, w http.ResponseWriter, r *http.Request) {
next := extractPath(r.URL.Query().Get(keyNextPage))
if s.Get(keyToken) == nil {
// User is not logged in.
if next == "" {
next = "/"
}
http.Redirect(w, r, f.AuthCodeURL(next), codeRedirect)
return
}
// No need to login, redirect to the next page.
http.Redirect(w, r, next, codeRedirect)
}
开发者ID:gorelease,项目名称:oauth2,代码行数:13,代码来源:oauth2.go
示例5: GetUserBySession
func (ctx *Context) GetUserBySession(sess session.Store) {
// sess.Set("uid", "123")
if uid, ok := sess.Get("uid").(string); ok {
o := orm.NewOrm()
user := models.User{Id: uid}
err := o.Read(&user)
ctx.User = &user
if err == nil {
ctx.IsSigned = true
}
}
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:13,代码来源:context.go
示例6: SignedInID
// SignedInID returns the id of signed in user.
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
if !models.HasEngine {
return 0
}
// Check access token.
if IsAPIPath(ctx.Req.URL.Path) {
tokenSHA := ctx.Query("token")
if len(tokenSHA) == 0 {
// Well, check with header again.
auHead := ctx.Req.Header.Get("Authorization")
if len(auHead) > 0 {
auths := strings.Fields(auHead)
if len(auths) == 2 && auths[0] == "token" {
tokenSHA = auths[1]
}
}
}
// Let's see if token is valid.
if len(tokenSHA) > 0 {
t, err := models.GetAccessTokenBySHA(tokenSHA)
if err != nil {
if models.IsErrAccessTokenNotExist(err) {
log.Error(4, "GetAccessTokenBySHA: %v", err)
}
return 0
}
t.Updated = time.Now()
if err = models.UpdateAccessToekn(t); err != nil {
log.Error(4, "UpdateAccessToekn: %v", err)
}
return t.UID
}
}
uid := sess.Get("uid")
if uid == nil {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserByID(id); err != nil {
if !models.IsErrUserNotExist(err) {
log.Error(4, "GetUserById: %v", err)
}
return 0
}
return id
}
return 0
}
开发者ID:nafrente,项目名称:gogs,代码行数:52,代码来源:auth.go
示例7: login
func login(ctx *macaron.Context, s session.Store, opt *Options) {
next := extractPath(ctx.Query(KEY_NEXT_PAGE))
if s.Get(KEY_TOKEN) == nil {
// User is not logged in.
if next == "" {
next = AppSubUrl + "/"
}
// println(111, opt.AuthCodeURL(next, "", ""))
ctx.Redirect(opt.AuthCodeURL(next, "", ""))
return
}
// No need to login, redirect to the next page.
ctx.Redirect(next)
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:14,代码来源:social.go
示例8: handleOAuth2Callback
func handleOAuth2Callback(f *oauth2.Config, s session.Store, w http.ResponseWriter, r *http.Request) {
next := extractPath(r.URL.Query().Get("state"))
code := r.URL.Query().Get("code")
t, err := f.Exchange(oauth2.NoContext, code)
if err != nil {
// Pass the error message, or allow dev to provide its own
// error handler.
http.Redirect(w, r, PathError, codeRedirect)
return
}
// Store the credentials in the session.
val, _ := json.Marshal(t)
s.Set(keyToken, val)
http.Redirect(w, r, next, codeRedirect)
}
开发者ID:gorelease,项目名称:oauth2,代码行数:15,代码来源:oauth2.go
示例9: handleOAuth2Callback
func handleOAuth2Callback(ctx *macaron.Context, s session.Store, opt *Options) {
next := extractPath(ctx.Query("state"))
code := ctx.Query("code")
t, err := opt.NewTransportFromCode(code)
if err != nil {
// Pass the error message, or allow dev to provide its own
// error handler.
println(err.Error())
ctx.Redirect(PathError)
return
}
// Store the credentials in the session.
val, _ := json.Marshal(t.Token())
s.Set(KEY_TOKEN, val)
ctx.Redirect(next)
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:16,代码来源:social.go
示例10: SignedInId
// SignedInId returns the id of signed in user.
func SignedInId(req *http.Request, sess session.Store) int64 {
if !models.HasEngine {
return 0
}
// API calls need to check access token.
if IsAPIPath(req.URL.Path) {
auHead := req.Header.Get("Authorization")
if len(auHead) > 0 {
auths := strings.Fields(auHead)
if len(auths) == 2 && auths[0] == "token" {
t, err := models.GetAccessTokenBySHA(auths[1])
if err != nil {
if err != models.ErrAccessTokenNotExist {
log.Error(4, "GetAccessTokenBySHA: %v", err)
}
return 0
}
t.Updated = time.Now()
if err = models.UpdateAccessToekn(t); err != nil {
log.Error(4, "UpdateAccessToekn: %v", err)
}
return t.UID
}
}
}
uid := sess.Get("uid")
if uid == nil {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserByID(id); err != nil {
if !models.IsErrUserNotExist(err) {
log.Error(4, "GetUserById: %v", err)
}
return 0
}
return id
}
return 0
}
开发者ID:pecastro,项目名称:gogs,代码行数:43,代码来源:auth.go
示例11: SignedInId
// SignedInId returns the id of signed in user.
func SignedInId(req *http.Request, sess session.Store) int64 {
if !models.HasEngine {
return 0
}
// API calls need to check access token.
if strings.HasPrefix(req.URL.Path, "/api/") {
auHead := req.Header.Get("Authorization")
if len(auHead) > 0 {
auths := strings.Fields(auHead)
if len(auths) == 2 && auths[0] == "token" {
t, err := models.GetAccessTokenBySha(auths[1])
if err != nil {
if err != models.ErrAccessTokenNotExist {
log.Error(4, "GetAccessTokenBySha: %v", err)
}
return 0
}
return t.Uid
}
}
}
uid := sess.Get("uid")
if uid == nil {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserById(id); err != nil {
if err != models.ErrUserNotExist {
log.Error(4, "GetUserById: %v", err)
}
return 0
}
return id
}
return 0
}
开发者ID:wxiangbo,项目名称:gogs,代码行数:39,代码来源:auth.go
示例12: logout
func logout(ctx *macaron.Context, s session.Store) {
next := extractPath(ctx.Query(KEY_NEXT_PAGE))
s.Delete(KEY_TOKEN)
ctx.Redirect(next)
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:5,代码来源:social.go
示例13: logout
func logout(s session.Store, w http.ResponseWriter, r *http.Request) {
next := extractPath(r.URL.Query().Get(keyNextPage))
s.Delete(keyToken)
http.Redirect(w, r, next, codeRedirect)
}
开发者ID:gorelease,项目名称:oauth2,代码行数:5,代码来源:oauth2.go
示例14: Logout
func (u *User) Logout(sess session.Store) {
sess.Delete("uid")
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:3,代码来源:user.go
示例15: Login
func (u *User) Login(sess session.Store) {
sess.Set("uid", u.Id)
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:3,代码来源:user.go
示例16: mySessionHandler
func mySessionHandler(sess session.Store) string {
sess.Set("session", "session middleware")
return sess.Get("session").(string)
}
开发者ID:james2doyle,项目名称:macaron-example,代码行数:4,代码来源:main.go
注:本文中的github.com/macaron-contrib/session.Store类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论