Beispiel #1
0
        public void DeleteExpiredTokensAsync()
        {
            DateTimeOffset now = DateTimeOffset.UtcNow;
            IQueryable <Models.DbModels.UserToken> ExpiredTokens = _tokens.GetAll().Where(x => x.RefreshTokenExpiresDateTime < now);

            if (ExpiredTokens != null && ExpiredTokens.Count() > 0)
            {
                _tokens.Delete(ExpiredTokens);
            }
        }
        public async Task DeleteExpiredTokensAsync()
        {
            var now        = DateTimeOffset.UtcNow;
            var userTokens = await _userTokenRepository.FindBy(x => x.RefreshTokenExpiresDateTime < now);

            if (userTokens.Count() > 0)
            {
                foreach (var item in userTokens)
                {
                    _userTokenRepository.Delete(item);
                }

                await _userTokenRepository.SaveChanges();
            }
        }
        public bool Invoke(string guid)
        {
            if (string.IsNullOrEmpty(guid))
            {
                return(false);
            }

            var userToken = userTokenRepository.FindBy(x => x.SecretToken == guid).Include(x => x.User).FirstOrDefault();

            if (userToken == null ||
                userToken.User.EmailConfirmedOn != null ||
                userToken.SecretTokenTimeStamp <= DateTime.UtcNow)
            {
                return(false);
            }

            userToken.User.EmailConfirmedOn = DateTime.UtcNow;

            userRepository.Edit(userToken.User);

            userTokenRepository.Delete(userToken);
            _unitOfWork.Save();

            return(true);
        }
Beispiel #4
0
        public bool Invoke(Guid id, string plainPassword)
        {
            if (id == Guid.Empty || string.IsNullOrEmpty(plainPassword))
            {
                return(false);
            }

            var userToEdit = userRepository.GetById(id);

            switch (userToEdit)
            {
            default:
                var salt = hasher.GenerateRandomSalt();
                userToEdit.PasswordHash = hasher.CreatePasswordHash(plainPassword, salt);
                userToEdit.PasswordSalt = salt;

                var tokenToDelete = userTokenRepository.FindBy(x => x.User == userToEdit).FirstOrDefault();

                if (tokenToDelete is null)
                {
                    return(false);
                }

                userTokenRepository.Delete(tokenToDelete);

                userRepository.Edit(userToEdit);
                _unitOfWork.Save();

                return(true);

            case null:
                return(false);
            }
        }
        public string Invoke(Guid userId)
        {
            if (userId == Guid.Empty)
            {
                return(string.Empty);
            }

            var user = userRepository.GetById(userId);

            if (user == null)
            {
                return(string.Empty);
            }

            var token = userTokenRepository.GetById(userId);

            if (token != null)
            {
                userTokenRepository.Delete(token);
            }

            var userToken = new DataAccess.Models.UserToken
            {
                User        = user,
                SecretToken = hasher.GenerateRandomGuid()
            };

            userTokenRepository.Add(userToken);
            _unitOfWork.Save();

            return(userToken.SecretToken);
        }
 public ResponseMessageDTO Kill(string username)
 {
     //We will call DAL method to delete the token by username of user
     _userTokenRepository.Delete(userToken => userToken.Username == username);
     if (_userTokenRepository.GetTokenByUsername(username) != null)
     {
         return(new ResponseMessageDTO(false, L("Delete_UserTokenFailed", username)));
     }
     return(new ResponseMessageDTO(true,
                                   L("Delete_UserTokenSuccess", username)));
 }
        public bool Invoke(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(false);
            }

            var userToken = userTokenRepository.FindBy(x => x.SecretToken == token).FirstOrDefault();

            if (userToken == null)
            {
                return(false);
            }

            userTokenRepository.Delete(userToken);
            _unitOfWork.Save();

            return(true);
        }
Beispiel #8
0
        public bool Invoke(Guid userTokenId)
        {
            if (userTokenId == Guid.Empty)
            {
                return(false);
            }

            var userToken = userTokenRepository.GetById(userTokenId);

            if (userToken == null)
            {
                return(false);
            }

            userTokenRepository.Delete(userToken);
            _unitOfWork.Save();

            return(true);
        }
Beispiel #9
0
 public Task DeleteByToken(string token)
 {
     return(userTokenRepository.Delete(token));
 }