public static VerificationCode get_object(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(null);
            }

            return(RedisAPI.Enabled ? RedisAPI.get_value <VerificationCode>(token) :
                   (Tokens.ContainsKey(token) ? Tokens[token] : null));
        }
Exemple #2
0
        public static Guid?get_user_id(string ticket)
        {
            if (string.IsNullOrEmpty(ticket))
            {
                return(null);
            }

            return(RedisAPI.Enabled ? RedisAPI.get_value <Guid?>(ticket) :
                   (!_Tickets.ContainsKey(ticket) ? (Guid?)null : _Tickets[ticket]));
        }
Exemple #3
0
        public static string new_token(string ticket)
        {
            if (string.IsNullOrEmpty(ticket))
            {
                return(string.Empty);
            }

            AccessTokenList lst   = get_token_list(ticket);
            string          token = AccessTokenList.new_token(lst);

            if (RedisAPI.Enabled)
            {
                RedisAPI.set_value <AccessTokenList>(get_redis_token_key(ticket), lst);
            }

            return(token);
        }
Exemple #4
0
        public static void new_ticket(string ticket, Guid userId)
        {
            if (string.IsNullOrEmpty(ticket))
            {
                return;
            }

            if (RedisAPI.Enabled)
            {
                RedisAPI.set_value <Guid?>(ticket, userId);
                RedisAPI.set_value(get_redis_key(userId), ticket);
            }
            else
            {
                _Tickets[ticket] = userId;
            }
        }
        protected bool update_ttl(string token)
        {
            if (_TTL <= 0)
            {
                return(false);
            }
            else
            {
                --_TTL;

                if (RedisAPI.Enabled && !string.IsNullOrEmpty(token))
                {
                    RedisAPI.set_value <VerificationCode>(token, this);
                }

                return(true);
            }
        }
Exemple #6
0
        public static AccessTokenList get_token_list(string ticket)
        {
            if (string.IsNullOrEmpty(ticket))
            {
                return(null);
            }

            if (RedisAPI.Enabled)
            {
                AccessTokenList lst = RedisAPI.get_value <AccessTokenList>(get_redis_token_key(ticket));
                return(lst == null ? new AccessTokenList() : lst);
            }
            else
            {
                if (!APITokens.ContainsKey(ticket))
                {
                    APITokens.Add(ticket, new AccessTokenList());
                }
                return(APITokens[ticket]);
            }
        }
        protected bool use()
        {
            if (_ExpirationDate.HasValue)
            {
                return(false);
            }

            reset_expiration_date();

            if (RedisAPI.Enabled)
            {
                RedisAPI.set_value <VerificationCode>(_Token, this);
            }
            else
            {
                Tokens[_Token] = this;
            }

            Task task = Task.Delay((TimeOut + 10) * 1000 * TotalTimeOutCoefficient)
                        .ContinueWith(t =>
            {
                if (RedisAPI.Enabled)
                {
                    RedisAPI.remove_key(_Token);
                }
                else
                {
                    lock (Tokens) { if (Tokens.ContainsKey(_Token))
                                    {
                                        Tokens.Remove(_Token);
                                    }
                    }
                }
            });

            return(true);
        }
Exemple #8
0
 public static string get_ticket(Guid userId)
 {
     return(RedisAPI.Enabled ? RedisAPI.get_value(get_redis_key(userId)) :
            _Tickets.Keys.Where(u => _Tickets[u] == userId).FirstOrDefault());
 }