Example #1
0
// Get the current signed in user
func GetSignedInUser(r *http.Request) *account.SignedUser {
	user := context.Get(r, context.SIGNEDID)
	if user == nil {
		return nil
	}
	return user.(*account.SignedUser)
}
Example #2
0
func IsSignedInUser(r *http.Request) bool {
	user := context.Get(r, context.SIGNEDID)
	if user == nil {
		return false
	}
	return true
}
Example #3
0
// Need request object, for reading session id from request context
func InsertData(r *http.Request, key string, value interface{}) {
	sid := context.Get(r, context.SID).(string)
	c := redis.Get()
	if _, err := c.Do("HMSET", sid, key, value); err != nil {
		panic(err.Error())
	}

	// Session storage id will be remove in 10 hours. Keep
	// redis database clean.
	c.Do("EXPIREAT", sid, time.Now().Add(time.Hour*10).Unix())
}
Example #4
0
// If value is not found, then return empty string
func ReadData(r *http.Request, key string) (interface{}, error) {

	var value string

	sid := context.Get(r, context.SID).(string)
	c := redis.Get()
	raw, err := redigo.Values(c.Do("HMGET", sid, key))

	redigo.Scan(raw, &value)
	if err != nil {
		return nil, err
	}
	return value, nil
}
Example #5
0
func DeleteData(r *http.Request, key string) {
	sid := context.Get(r, context.SID).(string)
	c := redis.Get()
	c.Do("HDEL", sid, key)
}
Example #6
0
func GetLang(r *http.Request) string {
	return context.Get(r, context.LANGUAGE).(string)
}