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();
            }
        }
Пример #2
0
        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);
        }
Пример #3
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);
            }
        }
Пример #4
0
        public UserTokenModel Invoke(Guid userId)
        {
            if (userId == Guid.Empty)
            {
                return(null);
            }

            var token = userTokenRepository.FindBy(x => x.User.Id == userId).FirstOrDefault();

            if (token == null)
            {
                return(null);
            }

            var userTokenModel = Mapper.Map <UserTokenModel>(token);

            return(userTokenModel);
        }
Пример #5
0
        public UserModel Invoke(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(null);
            }

            var result = userTokenRepository.FindBy(y => y.SecretToken == token).Include(x => x.User).FirstOrDefault();

            if (result == null)
            {
                return(null);
            }

            var user = AutoMapper.Mapper.Map <UserModel>(result.User);

            return(user);
        }
        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);
        }