Exemple #1
0
func Active(name string) bool {
	memstore.Start()
	defer memstore.Close()
	if featureExists, _ := redis.Bool(memstore.Do("HEXISTS", "feature.gates", name)); !featureExists {
		return false
	}
	return true
}
Exemple #2
0
func RetrieveActionByToken(token string) Action {
	memstore.Start()
	defer memstore.Close()
	if indexExists, _ := redis.Bool(memstore.Do("HEXISTS", "models.actions.indexes", token)); !indexExists {
		return Action{}
	}
	actionUUID, _ := redis.String(memstore.Do("HGET", "models.actions.indexes", token))
	return RetrieveActionByUUID(actionUUID)
}
Exemple #3
0
func (action *Action) Delete() {
	memstore.Start()
	defer memstore.Close()
	if actionExists, _ := redis.Bool(memstore.Do("HEXISTS", "models.actions", action.UUID)); !actionExists {
		return
	}
	memstore.Do("HDEL", "models.actions.indexes", action.Token)
	memstore.Do("HDEL", "models.actions", action.UUID)
	memstore.Do("ZREM", "models.actions.rank", action.UUID)
}
Exemple #4
0
func RetrieveActionByUUID(uuid string) Action {
	var action Action
	memstore.Start()
	defer memstore.Close()
	if actionExists, _ := redis.Bool(memstore.Do("HEXISTS", "models.actions", uuid)); !actionExists {
		return Action{}
	}
	actionString, _ := redis.String(memstore.Do("HGET", "models.actions", uuid))
	if err := json.Unmarshal([]byte(actionString), &action); err != nil {
		return Action{}
	}
	return action
}
Exemple #5
0
func (action *Action) Save() error {
	action.UserID = action.User.ID
	action.ClientID = action.Client.ID
	action.UUID = generateUUID()
	action.CreatedAt = time.Now().UTC()
	action.Token = GenerateRandomString(64)
	action.Moment = time.Now().UTC().Unix()
	action.ExpiresIn = shortestExpirationLength
	if err := validateModel("validate", action); err != nil {
		return err
	}
	memstore.Start()
	defer memstore.Close()
	actionJson, _ := json.Marshal(action)
	memstore.Do("HSET", "models.actions", action.UUID, actionJson)
	memstore.Do("HSET", "models.actions.indexes", action.Token, action.UUID)
	memstore.Do("ZADD", "models.actions.rank", action.Moment, action.UUID)
	return nil
}
Exemple #6
0
func SignInAttemptStatus(id string) string {
	memstore.Start()
	defer memstore.Close()

	if blockExists, _ := redis.Bool(memstore.Do("HEXISTS", "sign-in.blocked", id)); blockExists {
		return Blocked
	}
	if attemptExists, _ := redis.Bool(memstore.Do("HEXISTS", "sign-in.attempt", id)); attemptExists {
		reply, _ := redis.Int(memstore.Do("HGET", "sign-in.attempt", id))
		switch {
		case reply > 0 && reply <= attemptsUntilPreblock:
			return Clear
		case reply > attemptsUntilPreblock && reply <= attemptsUntilBlock:
			return Preblocked
		case reply > attemptsUntilBlock:
			return Blocked
		}
	}
	return Clear
}