public async Task <IActionResult> CompleteSetupAsync()
        {
            // Block request when setup was completed before
            if (_appSettingsManager.AppSettings != null)
            {
                return(BadRequest());
            }

            // Read POST body to SmtpMailTest object
            InitialConfiguration config;

            using (var reader = new StreamReader(Request.Body))
            {
                string body = await reader.ReadToEndAsync();

                if (string.IsNullOrWhiteSpace(body))
                {
                    return(BadRequest());
                }
                config = await InitialConfiguration.ParseJsonAsync(body);
            }

            // Validate data
            if (config == null || !config.Validate())
            {
                return(Ok(new FailureResponse("Configuration data not valid")));
            }

            // Create admin user
            var adminUser = new User(config.AdminUsername)
            {
                Email          = config.AdminEmail,
                EmailConfirmed = true
            };
            var result = await _userManager.CreateAsync(adminUser, config.AdminPw);

            if (!result.Succeeded)
            {
                return(Ok(new FailureResponse(string.Join(' ', result.Errors.Select(err => err.Description)))));
            }

            // Create roles
            await AddBuildInUserRole(Roles.AdminRole);
            await AddBuildInUserRole(Roles.CoordinatorRole);
            await AddBuildInUserRole(Roles.UserRole);

            // Add admin role to admin user
            await _userManager.AddToRoleAsync(adminUser, Roles.AdminRole);

            // Also add user role
            await _userManager.AddToRoleAsync(adminUser, Roles.UserRole);

            // Store basic app settings
            await _appSettingsManager.SaveSettingsAsync(config.BaseUrl, true, DefaultTemplate.Html);

            // Store SMTP notifier
            await _notifierManager.AddNotifierAsync(SmtpNotifierData.CreateFrom(config.Smtp));

            return(Ok(new SuccessResponse()));
        }
        public async Task <IActionResult> SaveGeneralAsync(
            [FromForm] string baseUrl,
            [FromForm] string allowRegistration,
            [FromForm] string htmlMessageTemplate)
        {
            // Check authorization
            if (!(await User.IsAdminAsync(_authorizationService)))
            {
                return(Unauthorized());
            }

            // Change settings
            await _appSettingsManager.SaveSettingsAsync(
                baseUrl,
                allowRegistration?.Equals("on", System.StringComparison.CurrentCultureIgnoreCase) ?? false,
                htmlMessageTemplate);

            // Show same page
            return(RedirectToAction("Index"));
        }