public async Task <IActionResult> Index() { // Check Data bool displayPage = await DisplayPage(); if (!displayPage) { _logger.LogWarning("User tried to access first time deployment page while not valid."); return(StatusCode((int)HttpStatusCode.NotFound)); } FirstTimeDeploymentViewModel viewModel = new FirstTimeDeploymentViewModel(); return(View(viewModel)); }
public async Task <IActionResult> Index(FirstTimeDeploymentViewModel viewModel) { // Check Data bool displayPage = await DisplayPage(); if (!displayPage) { _logger.LogWarning("User tried to post to first time deployment page while not valid."); return(StatusCode((int)HttpStatusCode.NotFound)); } // Check Password if (ModelState.IsValid) { if (viewModel.FirstTimeDeploymentPassword != _firstTimeDeploymentPassword) { // Dont give feedback to not help attackers _logger.LogWarning("User tried to create new admin user in first time deployment page with wrong password."); return(RedirectToAction("Login", "Account")); } try { IdentityResult result = await _userCreator.CreateUser(Url, Request.Scheme, viewModel.Name, viewModel.Email, viewModel.Password, RoleNames.Administrator); if (!result.Succeeded) { _logger.LogInformation("Error while creating user"); } } catch (Exception ex) { _logger.LogError(ex, "Error while creating user"); } return(RedirectToAction("Login", "Account")); } return(View(viewModel)); }