本文整理汇总了Golang中github.com/macaron-contrib/session.Store.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.Get方法的具体用法?Golang Store.Get怎么用?Golang Store.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/macaron-contrib/session.Store
的用法示例。
在下文中一共展示了Store.Get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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}
}
示例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
}
示例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)
}
示例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
}
}
}
示例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
}
示例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)
}
示例8: 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
}
示例9: 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
}
示例10: mySessionHandler
func mySessionHandler(sess session.Store) string {
sess.Set("session", "session middleware")
return sess.Get("session").(string)
}