예제 #1
0
        public Task SaveDbConnConfig(DbConnConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            ConfigCache.Save(Tenant, config);
            _shellSettings.ShellConfiguration[DbConnConfigConst.DataProvider] = config.DataProvider;
            _shellSettings.ShellConfiguration[config.ConnectionName]          = config.ConnectionString;
            return(_shellSettingsManager.SaveSettingsAsync(_shellSettings));
        }
예제 #2
0
        public async Task UpdateShellSettingsAsync(ShellSettings settings)
        {
            settings.Identifier = IdGenerator.GenerateId();
            await _shellSettingsManager.SaveSettingsAsync(settings);

            await ReloadShellContextAsync(settings);
        }
예제 #3
0
        public async Task <IActionResult> IndexPost(RegisterUserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var shellSettings = new ShellSettings
                {
                    Name             = viewModel.Handle,
                    RequestUrlPrefix = viewModel.Handle,
                    RequestUrlHost   = "",
                    // this should be a setting in the SaaS module
                    ["ConnectionString"] = "", //ComponentChangedEventArgs by giannis
                    //  ConnectionString = "",
                    //TablePrefix = "",
                    ["TablePrefix"] = "",
                    //  DatabaseProvider = "Sqlite",
                    ["DatabaseProvider"] = "Sqlite",
                    State = TenantState.Uninitialized,
                    // Secret = Guid.NewGuid().ToString(),
                    //RecipeName = "Blog"
                };


                await _shellSettingsManager.SaveSettingsAsync(shellSettings);

                var shellContext = await _shellHost.GetOrCreateShellContextAsync(shellSettings);

                var confirmationLink = Url.Action("Confirm", "Home",
                                                  new { email = viewModel.Email, handle = viewModel.Handle, siteName = viewModel.SiteName },
                                                  Request.Scheme);

                var message = new OrchardCore.Email.MailMessage();
                message.From       = "*****@*****.**"; // new MailAddress("*****@*****.**", "Orchard SaaS");
                message.To         = viewModel.Email;     ////.Add(viewModel.Email);
                message.IsBodyHtml = true;
                message.Body       = $"Click <a href=\"{HttpUtility.HtmlEncode(confirmationLink)}\">this link</a>";
                ;


                await _smtpService.SendAsync(message);

                return(RedirectToAction(nameof(Success)));
            }

            return(View("Index", viewModel));
        }
        public async Task <IActionResult> IndexPost(RegisterUserViewModel model)
        {
            if (!model.AcceptTerms)
            {
                ModelState.AddModelError(nameof(RegisterUserViewModel.AcceptTerms), S["Please, accept the terms and conditions."]);
            }

            if (!string.IsNullOrEmpty(model.Handle) && !Regex.IsMatch(model.Handle, @"^\w+$"))
            {
                ModelState.AddModelError(nameof(RegisterUserViewModel.Handle), S["Invalid tenant name. Must contain characters only and no spaces."]);
            }

            if (ModelState.IsValid)
            {
                if (_shellHost.TryGetSettings(model.Handle, out var shellSettings))
                {
                    ModelState.AddModelError(nameof(RegisterUserViewModel.Handle), S["This site name already exists."]);
                }
                else
                {
                    shellSettings = new ShellSettings
                    {
                        Name             = model.Handle,
                        RequestUrlPrefix = model.Handle.ToLower(),
                        RequestUrlHost   = null,
                        State            = TenantState.Uninitialized
                    };
                    shellSettings["RecipeName"]       = model.RecipeName;
                    shellSettings["DatabaseProvider"] = "Sqlite";

                    await _shellSettingsManager.SaveSettingsAsync(shellSettings);

                    var shellContext = await _shellHost.GetOrCreateShellContextAsync(shellSettings);

                    var recipes = await _setupService.GetSetupRecipesAsync();

                    var recipe = recipes.FirstOrDefault(x => x.Name == model.RecipeName);

                    if (recipe == null)
                    {
                        ModelState.AddModelError(nameof(RegisterUserViewModel.RecipeName), S["Invalid recipe name."]);
                    }

                    var adminName     = defaultAdminName;
                    var adminPassword = GenerateRandomPassword();
                    var siteName      = model.SiteName;
                    var siteUrl       = GetTenantUrl(shellSettings);

                    var dataProtector     = _dataProtectionProvider.CreateProtector(dataProtectionPurpose).ToTimeLimitedDataProtector();
                    var encryptedPassword = dataProtector.Protect(adminPassword, _clock.UtcNow.Add(new TimeSpan(24, 0, 0)));
                    var confirmationLink  = Url.Action(nameof(Confirm), "Home", new { email = model.Email, handle = model.Handle, siteName = model.SiteName, ep = encryptedPassword }, Request.Scheme);

                    var message = new MailMessage();
                    if (emailToBcc)
                    {
                        message.Bcc = _smtpSettingsOptions.Value.DefaultSender;
                    }
                    message.To         = model.Email;
                    message.IsBodyHtml = true;
                    message.Subject    = emailSubject;
                    message.Body       = S[$"Hello,<br><br>Your demo site '{siteName}' has been created.<br><br>1) Setup your site by opening <a href=\"{confirmationLink}\">this link</a>.<br><br>2) Log into the <a href=\"{siteUrl}/admin\">admin</a> with these credentials:<br>Username: {adminName}<br>Password: {adminPassword}"];

                    await _smtpService.SendAsync(message);

                    return(RedirectToAction(nameof(Success)));
                }
            }

            return(View(nameof(Index), model));
        }
예제 #5
0
        public async Task UpdateShellSettingsAsync(ShellSettings settings)
        {
            await _shellSettingsManager.SaveSettingsAsync(settings);

            await ReloadShellContextAsync(settings);
        }