コード例 #1
0
        private bool IsModelValid(CustomSetupViewModel model)
        {
            if (String.IsNullOrEmpty(model.Password))
            {
                ModelState.AddModelError(nameof(model.Password), S["The password is required."]);
            }

            if (model.Password != model.PasswordConfirmation)
            {
                ModelState.AddModelError(nameof(model.PasswordConfirmation), S["The password confirmation doesn't match the password."]);
            }

            if (!_emailAddressValidator.Validate(model.Email))
            {
                ModelState.AddModelError(nameof(model.Email), S["Invalid email."]);
            }

            if (!ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(_shellSettings["Description"]))
                {
                    model.Description = _shellSettings["Description"];
                }
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public async Task <ActionResult> IndexPOST(CustomSetupViewModel model)
        {
            if (!await IsValidRequest(model.Secret))
            {
                return(BadRequest(S["Error with tenant setup link. Please contact support to issue a new link"]));
            }
            if (!IsModelValid(model))
            {
                return(View(model));
            }

            var setupContext = await CreateSetupContext(model.SiteName, model.SiteTimeZone);

            await _setupService.SetupAsync(setupContext);

            // Check if a component in the Setup failed
            if (setupContext.Errors.Any())
            {
                foreach (var error in setupContext.Errors)
                {
                    ModelState.AddModelError(error.Key, error.Value);
                }
                return(View(model));
            }

            var shellSetting = await _shellSettingsManager.LoadSettingsAsync(_shellSettings.Name);

            await(await _shellHost.GetScopeAsync(shellSetting)).UsingAsync(async scope =>
            {
                void reportError(string key, string message)
                {
                    setupContext.Errors[key] = message;
                }

                // Invoke modules to react to the custom setup event
                var customsetupEventHandlers = scope.ServiceProvider.GetServices <ICustomTenantSetupEventHandler>();
                var logger = scope.ServiceProvider.GetRequiredService <ILogger <CustomSetupController> >();
                await customsetupEventHandlers.InvokeAsync(x => x.Setup(model.Email, model.Password, "CourseAdmin", reportError), logger);
            });

            return(Redirect($"~/{_adminOptions.AdminUrlPrefix}"));
        }