public override async Task <InstallSetupResult?> ExecuteAsync(UserModel user) { IUser?admin = _userService.GetUserById(Constants.Security.SuperUserId); if (admin == null) { throw new InvalidOperationException("Could not find the super user!"); } admin.Email = user.Email.Trim(); admin.Name = user.Name.Trim(); admin.Username = user.Email.Trim(); _userService.Save(admin); BackOfficeIdentityUser?membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserIdAsString); if (membershipUser == null) { throw new InvalidOperationException( $"No user found in membership provider with id of {Constants.Security.SuperUserIdAsString}."); } //To change the password here we actually need to reset it since we don't have an old one to use to change var resetToken = await _userManager.GeneratePasswordResetTokenAsync(membershipUser); if (string.IsNullOrWhiteSpace(resetToken)) { throw new InvalidOperationException("Could not reset password: unable to generate internal reset token"); } IdentityResult resetResult = await _userManager.ChangePasswordWithResetAsync(membershipUser.Id, resetToken, user.Password.Trim()); if (!resetResult.Succeeded) { throw new InvalidOperationException("Could not reset password: "******", ", resetResult.Errors.ToErrorMessage())); } _metricsConsentService.SetConsentLevel(user.TelemetryLevel); if (user.SubscribeToNewsLetter) { var values = new NameValueCollection { { "name", admin.Name }, { "email", admin.Email } }; var content = new StringContent(JsonConvert.SerializeObject(values), Encoding.UTF8, "application/json"); HttpClient httpClient = _httpClientFactory.CreateClient(); try { HttpResponseMessage response = httpClient.PostAsync("https://shop.umbraco.com/base/Ecom/SubmitEmail/installer.aspx", content).Result; } catch { /* fail in silence */ } } return(null); }
public IActionResult SetConsentLevel([FromBody] TelemetryResource telemetryResource) { if (!ModelState.IsValid) { return(BadRequest()); } _metricsConsentService.SetConsentLevel(telemetryResource.TelemetryLevel); return(Ok()); }