Example #1
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);
        }
Example #2
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);
            }
        }
        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);
        }