Exemplo n.º 1
0
func (u *User) GetNotification(pushType, pushToken string) (bool, error) {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	token := fmt.Sprintf("%s:%s", pushType, pushToken)
	alert, err := redis.Int(r.Do("SISMEMBER", u.PushTokenListKey(), token))

	return alert == 1, err
}
Exemplo n.º 2
0
func (um *UserManager) GetUserByKey(key string) (*User, error) {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	id, err := redis.String(r.Do("HGET", "key", key))
	if err != nil {
		return nil, &CacheNotFound{key: key}
	}
	return um.GetUserById(id)
}
Exemplo n.º 3
0
func (um *UserManager) CheckAllowedUser(email string) bool {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	allowed, err := redis.Int(r.Do("SISMEMBER", "allowed_user", email))
	if err != nil {
		log.Println("CheckAllowedUser Error:", err)
		return false
	}
	return allowed == 1
}
Exemplo n.º 4
0
func (um *UserManager) GetUserByKey(key string) (*User, error) {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	redisKey := "key:" + key
	id, err := redis.String(r.Do("GET", redisKey))
	if err != nil {
		return nil, &CacheNotFound{key: key}
	}
	r.Do("EXPIRE", redisKey, 172800)
	return um.GetUserById(id)
}
Exemplo n.º 5
0
func (um *UserManager) RegisterUser(id string) string {
	// make key
	seed, _ := time.Now().GobEncode()
	h := hmac.New(sha1.New, seed)
	io.WriteString(h, id)
	key := fmt.Sprintf("%0x", h.Sum(nil))
	um.GetUserById(id)

	r := common.DefaultRedisPool().Get()
	defer r.Close()
	_, err := r.Do("HSET", "key", key, id)
	if err != nil {
		log.Println("RegisterUser: ", err)
	}
	return key
}
func LoadDb() {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	// 서버 목록들을 읽어와서 IRCClient를 생성하고 접속
	reply, err := redis.Values(r.Do("KEYS", "servers:*"))
	if err != nil {
		log.Println("LoadDb: ", err)
		os.Exit(1)
	}
	for _, key := range reply {
		key, _ := redis.String(key, nil)
		var servers []*common.IRCServer
		err = common.RedisSliceLoad(key, &servers)
		if err != nil {
			log.Println("LoadDb: ", err)
			os.Exit(1)
		}
		for _, server := range servers {
			server.Active = false
			ircMgr.register <- NewClient(server)
		}
	}

	// 채널 목록을 읽어와서 채널을 추가
	reply, err = redis.Values(r.Do("KEYS", "channels:*"))
	if err != nil {
		log.Println("LoadDb: ", err)
		os.Exit(1)
	}
	for _, key := range reply {
		key, _ := redis.String(key, nil)
		var channels []*common.IRCChannel
		err = common.RedisSliceLoad(key, &channels)
		if err != nil {
			log.Println("LoadDb: ", err)
			os.Exit(1)
		}
		for _, channel := range channels {
			c := ircMgr.GetClient(channel.UserId, channel.ServerId)
			channel.Joined = false
			c.AddChannel(channel.Name)
		}
	}
}