Esempio n. 1
0
        public Task RemoveTokenAsync(ApplicationUser user, string loginProvider, string name, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrWhiteSpace(loginProvider))
            {
                throw new ArgumentNullException(nameof(loginProvider));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var userTokenEntity = _userTokenRepository.GetById(new UserTokenKey {
                UserId = user.Id, LoginProvider = loginProvider, Name = name
            });

            if (userTokenEntity != null)
            {
                _userTokenRepository.Remove(userTokenEntity);
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
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);
        }