Esempio n. 1
0
        public bool DeleteByUserId(int userId)
        {
            var tokenRepo = new TokenRepository();

            tokenRepo.Delete(tokenRepo.GetAll().Where(x => x.UserId == userId).Select(x => x.TokenId));
            tokenRepo.Save();

            var isNotDeleted = tokenRepo.GetAll().Select(x => x.UserId == userId).Any();

            return(!isNotDeleted);
        }
Esempio n. 2
0
        public bool Kill(string tokenId)
        {
            var tokenRepo = new TokenRepository();
            var t         = tokenRepo.GetAll().Where(x => x.AuthToken == tokenId).Select(s => s.TokenId);

            tokenRepo.Delete(t);
            tokenRepo.Save();
            var isNotDeleted = tokenRepo.GetAll().Select(x => x.AuthToken == tokenId).Any();

            if (isNotDeleted)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        public bool ValidateToken(string tokenId)
        {
            var tokenRepo = new TokenRepository();
            var token     = (from tokens in tokenRepo.GetAll()
                             where tokens.AuthToken == tokenId && tokens.ExpiresOn > DateTime.Now
                             select tokens).FirstOrDefault();

            if (token != null && !(DateTime.Now > token.ExpiresOn))
            {
                //ConfigurationManager.AppSettings["AuthTokenExpiry"]
                token.ExpiresOn = token.ExpiresOn.AddSeconds(
                    Convert.ToDouble(60 * 3));
                tokenRepo.Update(token);
                tokenRepo.Save();
                return(true);
            }
            return(false);
        }