コード例 #1
0
 public UserController(IConfiguration configuration, EmailService emailService, PoliceComplainsContext context,
                       DataProtectionService dataProtectionServiceService)
 {
     _configuration         = configuration;
     _emailService          = emailService;
     _dataProtectionService = dataProtectionServiceService;
     _context = context;
 }
コード例 #2
0
 public DashboardController(DataProtectionService dataProtectionService, PoliceComplainsContext context,
                            IHostingEnvironment env, EmailService emailService, IConfiguration configuration)
 {
     _dataProtectionService = dataProtectionService;
     _configuration         = configuration;
     _emailService          = emailService;
     _context = context;
     _env     = env;
 }
コード例 #3
0
        protected override void OnInitialized()
        {
            var status = DataProtectionService.Status();

            if (status != ProtectionStatus.Activate)
            {
                NavigationManager.NavigateTo("");
            }
        }
コード例 #4
0
        public void EncryptDecrypt_Fail(string text, string key)
        {
            // Arrange
            DataProtectionService service = new DataProtectionService();

            // Act
            string encrypted = service.Encrypt(text, key);
            string decrypted = service.Decrypt(encrypted, key.Substring(1));

            // Assert
            Assert.NotEmpty(encrypted);
            Assert.Empty(decrypted);
            Assert.NotEqual(text, encrypted);
        }
コード例 #5
0
        public async void Authenticate_Success()
        {
            // Arrange
            ApplicationDbContext   dbContext             = GetApplicationDbContext(_users[1]);
            IDataProtectionService dataProtectionService = new DataProtectionService();
            IUserRepository        userRepository        = new UserRepository(dbContext, dataProtectionService);
            AccountService         service = new AccountService(userRepository, dataProtectionService);

            // Act
            UserEntity user = await service.Authenticate(_users[1], CancellationToken.None);

            // Assert
            Assert.NotNull(user);
            Assert.NotNull(user.Password);
        }
コード例 #6
0
        public async void Authenticate_WrongUsername_Fail()
        {
            // Arrange
            ApplicationDbContext   dbContext             = GetApplicationDbContext(_users[1]);
            IDataProtectionService dataProtectionService = new DataProtectionService();
            IUserRepository        userRepository        = new UserRepository(dbContext, dataProtectionService);
            AccountService         service = new AccountService(userRepository, dataProtectionService);

            _users[1].Username = _users[1].Username.Substring(1);

            // Act
            UserEntity user = await service.Authenticate(_users[1], CancellationToken.None);

            // Assert
            Assert.Null(user);
        }
コード例 #7
0
        public async void Register_Success()
        {
            // Arrange
            ApplicationDbContext   dbContext             = GetApplicationDbContext();
            IDataProtectionService dataProtectionService = new DataProtectionService();
            IUserRepository        userRepository        = new UserRepository(dbContext, dataProtectionService);
            AccountService         service = new AccountService(userRepository, dataProtectionService);

            // Act
            UserEntity user = await service.Register(_users[1], CancellationToken.None);

            // Assert
            Assert.NotNull(user);
            Assert.Null(user.Password);
            Assert.NotEqual(_users[1].Password, dbContext.Users.First().Password);
        }
コード例 #8
0
        public async void GetUsers_Success()
        {
            // Arrange
            ApplicationDbContext   dbContext             = GetApplicationDbContext(_users.ToArray());
            IDataProtectionService dataProtectionService = new DataProtectionService();
            IUserRepository        userRepository        = new UserRepository(dbContext, dataProtectionService);
            AccountService         service = new AccountService(userRepository, dataProtectionService);

            // Act
            IEnumerable <UserEntity> users = await service.GetUsers(CancellationToken.None);

            // Assert
            Assert.NotNull(users);
            Assert.Equal(_users.Count, users.Count());
            foreach (UserEntity user in users)
            {
                Assert.Null(user.Password);
            }
        }
コード例 #9
0
        private ApplicationDbContext GetApplicationDbContext(params UserEntity[] users)
        {
            ApplicationDbContext dbContext = ApplicationDbContextSqliteInMemory;

            if (users != null)
            {
                DataProtectionService dataProtectionService = new DataProtectionService();
                foreach (UserEntity user in users)
                {
                    UserEntity newUser = new UserEntity {
                        Id = user.Id, Username = user.Username
                    };
                    newUser.Password = dataProtectionService.HashPassword(user.Password);
                    dbContext.Users.AddRange(newUser);
                }

                dbContext.SaveChanges();
            }
            return(dbContext);
        }
コード例 #10
0
 private async Task ActivateAsync()
 {
     try
     {
         await ButtonSpinner.SpinAsync(async() =>
         {
             var result = await DataProtectionService.ActivateProtectionAsync(Input.Password);
             if (!result)
             {
                 ValidationErrorMessage.DisplayError(nameof(InputModel.Password), "Invalid password");
                 return;
             }
             NavigationManager.NavigateTo("");
         });
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
         await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
     }
 }
コード例 #11
0
 private async Task ChangeDataProtectionPasswordAsync()
 {
     try
     {
         await Button.SpinAsync(async() =>
         {
             var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
             await DataProtectionService.ChangeProtectionPasswordAsync(CurrentPassword.OldPassword, CurrentPassword.NewPassword);
             await ToastService.ShowToastAsync("Data protection password updated.", ToastType.Success);
             Logger.LogInformation($"Data protection password updated by {authState.User.Identity.Name}");
             await ModalDialogClose();
         });
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
         await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
     }
     finally
     {
         await ModalDialogCancel();
     }
 }
コード例 #12
0
 private async Task EnableDataProtectionAsync()
 {
     try
     {
         await ButtonSpinner.SpinAsync(async() =>
         {
             var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
             await DataProtectionService.EnableProtectionAsync(NewPassword.Password);
             await Refresh.InvokeAsync(this);
             await ToastService.ShowToastAsync("Data protection enabled.", ToastType.Success);
             await SynchronizationService.UpdateDataProtection(ExceptPageId);
             Logger.LogInformation($"Data protection enabled by {authState.User.Identity.Name}");
         });
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
         await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
     }
     finally
     {
         await ModalDialogService.CloseAsync();
     }
 }
コード例 #13
0
 private void ProtectionStatus()
 {
     Status = DataProtectionService.Status();
     StateHasChanged();
 }