public virtual async Task <ActionResult> RejectTransformToOrganization(string accountNameToTransform, string token) { var adminUser = GetCurrentUser(); string message; var accountToTransform = UserService.FindByUsername(accountNameToTransform); if (accountToTransform == null) { message = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_OrganizationAccountDoesNotExist, accountNameToTransform); } else { if (await UserService.RejectTransformUserToOrganizationRequest(accountToTransform, adminUser, token)) { var emailMessage = new OrganizationTransformRejectedMessage(_config, accountToTransform, adminUser, isCanceledByAdmin: true); await MessageService.SendMessageAsync(emailMessage); TelemetryService.TrackOrganizationTransformDeclined(accountToTransform); message = string.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_Rejected, accountNameToTransform); } else { message = Strings.TransformAccount_FailedMissingRequestToCancel; } } TempData["Message"] = message; return(RedirectToAction(actionName: "Home", controllerName: "Pages")); }
public virtual async Task <ActionResult> CancelTransformToOrganization(string token) { var accountToTransform = GetCurrentUser(); var adminUser = accountToTransform.OrganizationMigrationRequest?.AdminUser; if (await UserService.CancelTransformUserToOrganizationRequest(accountToTransform, token)) { var emailMessage = new OrganizationTransformRejectedMessage(_config, accountToTransform, adminUser, isCanceledByAdmin: false); await MessageService.SendMessageAsync(emailMessage); TelemetryService.TrackOrganizationTransformCancelled(accountToTransform); TempData["Message"] = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_Cancelled); } else { TempData["ErrorMessage"] = Strings.TransformAccount_FailedMissingRequestToCancel; } return(RedirectToAction(actionName: "Home", controllerName: "Pages")); }
public virtual async Task <ActionResult> TransformToOrganization(TransformAccountViewModel transformViewModel) { var accountToTransform = GetCurrentUser(); var adminUsername = transformViewModel.AdminUsername; if (Regex.IsMatch(adminUsername, GalleryConstants.EmailValidationRegex, RegexOptions.None, GalleryConstants.EmailValidationRegexTimeout)) { ModelState.AddModelError(string.Empty, Strings.TransformAccount_AdminNameIsEmail); return(View(transformViewModel)); } var adminUser = UserService.FindByUsername(adminUsername); if (adminUser == null) { ModelState.AddModelError(string.Empty, string.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminAccountDoesNotExist, adminUsername)); return(View(transformViewModel)); } if (!UserService.CanTransformUserToOrganization(accountToTransform, adminUser, out var errorReason)) { ModelState.AddModelError(string.Empty, errorReason); return(View(transformViewModel)); } // Get the user from the previous organization migration request (if there was one) so we can notify them that their request has been cancelled. var existingTransformRequestUser = accountToTransform.OrganizationMigrationRequest?.AdminUser; await UserService.RequestTransformToOrganizationAccount(accountToTransform, adminUser); if (existingTransformRequestUser != null) { var emailMessage = new OrganizationTransformRejectedMessage(_config, accountToTransform, existingTransformRequestUser, isCanceledByAdmin: false); await MessageService.SendMessageAsync(emailMessage); } var organizationTransformRequestMessage = new OrganizationTransformRequestMessage( _config, accountToTransform, adminUser, profileUrl: Url.User(accountToTransform, relativeUrl: false), confirmationUrl: Url.ConfirmTransformAccount(accountToTransform, relativeUrl: false), rejectionUrl: Url.RejectTransformAccount(accountToTransform, relativeUrl: false)); await MessageService.SendMessageAsync(organizationTransformRequestMessage); var organizationTransformInitiatedMessage = new OrganizationTransformInitiatedMessage( _config, accountToTransform, adminUser, cancellationUrl: Url.CancelTransformAccount(accountToTransform, relativeUrl: false)); await MessageService.SendMessageAsync(organizationTransformInitiatedMessage); TelemetryService.TrackOrganizationTransformInitiated(accountToTransform); // sign out pending organization and prompt for admin sign in OwinContext.Authentication.SignOut(); TempData[GalleryConstants.ReturnUrlMessageViewDataKey] = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_SignInToConfirm, adminUser.Username, accountToTransform.Username); var returnUrl = Url.ConfirmTransformAccount(accountToTransform); return(Redirect(Url.LogOn(returnUrl))); }