Esempio n. 1
0
        public async Task VerifyUserAsync(VerifyUserDto dto)
        {
            var user = await _unitOfWork.GetRepository <ADUser>().GetFirstOrDefaultAsync(x => x.ADUserEmail == dto.Email);

            if (user == null)
            {
                throw new BusinessException("Không tìm thấy email!!!");
            }

            if (user.ADUserStatus != UserStatus.NotValidatedEmail)
            {
                throw new AccountAlreadyVerifyException("Tài khoản đã được xác thực!!!");
            }

            if (_dataProtectorUserTokenService.ValidateVerifyUserToken(user.Id, dto.ActiveToken))
            {
                user.ADUserStatus = UserStatus.Active;

                await _unitOfWork.GetRepository <ADUser>().UpdateAsync(user);

                await _dataProtectorUserTokenService.DeleteTokenAsync(dto.ActiveToken);

                await _unitOfWork.CompleteAsync();
            }
            else
            {
                throw new VerifyAccountFailedException("Tài khoản xác thực lỗi.");
            }
        }
Esempio n. 2
0
        public async Task <ServiceResult> ResetPasswordWithTokenAsync(ResetPasswordDto dto)
        {
            var user = await GetLoginByEmailAsync(dto.Email);

            if (user == null)
            {
                throw new EntityNotFoundException();
            }

            await CheckTokenExistAsync(dto.Token);

            if (!_dataProtectorUserTokenService.ValidateResetPasswordToken(user.Id, dto.Token))
            {
                return(ServiceResult.Failed(new ServiceError("InvalidResetPasswordToken", "Invalid token")));
            }

            user.ADUserPassword = LoginHelper.EncryptPassword(dto.Password);
            await _loginRepository.UpdateAsync(user);

            await _dataProtectorUserTokenService.DeleteTokenAsync(dto.Token);

            await _unitOfWork.CompleteAsync();

            return(ServiceResult.Success);
        }