Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#495 Added RecipeExtraParams to SetupContext for simplifying Custom Setup. NOT MERGE WIP #624

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Orchard.Recipes.Models;
using Orchard.Setup.Services;
using Orchard.Setup.ViewModels;
using Orchard.DisplayManagement;
using Microsoft.Extensions.Primitives;

namespace Orchard.Setup.Controllers
{
Expand Down Expand Up @@ -128,7 +130,8 @@ public async Task<ActionResult> IndexPOST(SetupViewModel model)
AdminEmail = model.Email,
AdminPassword = model.Password,
Errors = new Dictionary<string, string>(),
Recipe = selectedRecipe
Recipe = selectedRecipe,
RecipeExtraParams = Request.Form.ToDictionary(keyValue => keyValue.Key, keyValue => keyValue.Value.ToString())
};

if (!model.DatabaseProviderPreset)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Orchard.Recipes.Models;
using Microsoft.Extensions.Primitives;
using Orchard.Recipes.Models;
using System.Collections.Generic;

namespace Orchard.Setup.Services
Expand All @@ -12,6 +13,7 @@ public class SetupContext
public string DatabaseProvider { get; set; }
public string DatabaseConnectionString { get; set; }
public string DatabaseTablePrefix { get; set; }
public IDictionary<string, string> RecipeExtraParams { get; set; }
public IEnumerable<string> EnabledFeatures { get; set; }
public RecipeDescriptor Recipe { get; set; }
public IDictionary<string, string> Errors { get; set; }
Expand Down
22 changes: 11 additions & 11 deletions src/OrchardCore.Modules/Orchard.Setup/Services/SetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Threading.Tasks;
using YesSql.Core.Services;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Primitives;

namespace Orchard.Setup.Services
{
Expand Down Expand Up @@ -181,18 +182,17 @@ await scope
// to query the current execution.
//await Task.Run(async () =>
//{
await recipeExecutor.ExecuteAsync(executionId, context.Recipe, new
{
SiteName = context.SiteName,
AdminUsername = context.AdminUsername,
AdminEmail = context.AdminEmail,
AdminPassword = context.AdminPassword,
DatabaseProvider = context.DatabaseProvider,
DatabaseConnectionString = context.DatabaseConnectionString,
DatabaseTablePrefix = context.DatabaseTablePrefix
});
var recipeParams = context.RecipeExtraParams ?? new Dictionary<string,string>();
recipeParams[nameof(context.SiteName)] = context.SiteName;
recipeParams[nameof(context.AdminUsername)] = context.AdminUsername;
recipeParams[nameof(context.AdminEmail)] = context.AdminEmail;
recipeParams[nameof(context.AdminPassword)] = context.AdminPassword;
recipeParams[nameof(context.DatabaseProvider)] = context.DatabaseProvider;
recipeParams[nameof(context.DatabaseConnectionString)] = context.DatabaseConnectionString;
recipeParams[nameof(context.DatabaseTablePrefix)] = context.DatabaseTablePrefix;

await recipeExecutor.ExecuteAsync(executionId, context.Recipe, recipeParams);
//});

}
}

Expand Down
202 changes: 202 additions & 0 deletions src/OrchardCore.Modules/Orchard.Setup/Views/Setup.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
@using Orchard.Setup.ViewModels
@using System.Linq
@using Orchard.Setup.Controllers
@using Microsoft.AspNetCore.Builder
@using Microsoft.AspNetCore.Html
@using System.IO;
@inject Microsoft.AspNetCore.Mvc.Localization.IViewLocalizer T
@inject Microsoft.Extensions.Options.IOptions<IdentityOptions> identityOptions
@model Orchard.Setup.ViewModels.SetupViewModel

@{
var defaultRecipe = Model.Recipes.FirstOrDefault(x => x.Name == Model.RecipeName) ?? Model.Recipes.First();
var options = identityOptions.Value;
var passwordOptions = new HtmlContentBuilder();
IHtmlContent separator = HtmlString.Empty;

if (options.Password.RequireNonAlphanumeric)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one non-alphanumeric"]);
separator = T[", "];
}

if (options.Password.RequireUppercase)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one uppercase"]);
separator = T[", "];
}

if (options.Password.RequireLowercase)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one lowercase"]);
separator = T[", "];
}

if (options.Password.RequireDigit)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one digit"]);
separator = T[", "];
}

if (separator != HtmlString.Empty)
{
separator = T[" and "];
}

passwordOptions.AppendHtml(separator).AppendHtml(T["{0} characters in total", options.Password.RequiredLength]);

var passwordTooltip = T["Password must have at least {0}.", passwordOptions];
}

<form asp-action="Index">

<div class="jumbotron">
<h1>@T["SETUP"]</h1>
<p class="lead">@T["Please answer a few questions to configure your site."]</p>
</div>

<div class="row">
<fieldset class="form-group col-md-6" asp-validation-class-for="@Model.SiteName">
<div>
<label asp-for="@Model.SiteName">@T["What is the name of your site?"]</label>
<input asp-for="@Model.SiteName" class="form-control" autofocus />
<span asp-validation-for="@Model.SiteName" class="text-danger">@T["The site name is required."]</span>
<span class="text-muted form-text small">@T["This is used as the default title of your pages."]</span>
</div>
</fieldset>
<fieldset class="form-group col-md-6">
<input type="hidden" asp-for="@Model.RecipeName" />
<nav>
<div asp-validation-class-for="@Model.RecipeName">
<label asp-for="@Model.SiteName">@T["Recipe"]</label>
<div id="recipes" class="dropdown">
<button id="recipeButton" title="@defaultRecipe.Description" class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@defaultRecipe.DisplayName
</button>
<div class="dropdown-menu">
@foreach (var recipe in Model.Recipes.OrderBy(x => x.Name))
{
<a href="#" data-recipe-name="@recipe.Name" data-recipe-description="@recipe.Description" data-recipe-display-name="@recipe.DisplayName" class="dropdown-item">@recipe.DisplayName <span class="text-muted form-text small">@recipe.Description</span></a>
}
</div>
</div>
<span class="text-muted form-text small">@T["Recipes allow you to setup your site with additional pre-configured options, features and settings out of the box."]</span>

</div>
</nav>
</fieldset>
</div>
@if (!Model.TablePrefixPreset || !Model.ConnectionStringPreset || !Model.DatabaseProviderPreset)
{
<h6>
@T["Database"]
<span class="text-muted form-text small">@T["The database is used to store the site's configuration and its contents. You can specify a custom table prefix if you intend to reuse the same database for multiple sites."]</span>
</h6>
}
<div class="row">
@if (Model.DatabaseProviderPreset)
{
<input asp-for="@Model.DatabaseProvider" type="hidden" />
<span asp-validation-for="@Model.DatabaseProvider" class="text-danger"></span>
}
else
{
<div class="form-group col-md-6">
<label asp-for="@Model.DatabaseProvider">@T["What type of database to use?"]</label>
<select asp-for="@Model.DatabaseProvider" class="form-control">
@foreach (var provider in Model.DatabaseProviders)
{
<option value="@provider.Value" data-connection-string="@provider.HasConnectionString">@provider.Name</option>
}
</select>
<span asp-validation-for="@Model.DatabaseProvider" class="text-danger"></span>
</div>
}

@if (Model.TablePrefixPreset)
{
<input asp-for="@Model.TablePrefix" type="hidden" />
}
else
{
<div class="form-group col-md-6" asp-validation-class-for="@Model.TablePrefix">
<label asp-for="@Model.TablePrefix">@T["Table Prefix"]</label>
<input asp-for="@Model.TablePrefix" class="form-control" />
<span asp-validation-for="@Model.TablePrefix" class="text-danger"></span>
</div>
}
</div>

@if (Model.ConnectionStringPreset)
{
<input asp-for="@Model.ConnectionString" type="hidden" />
}
else
{
<fieldset class="row connectionString" asp-validation-class-for="@Model.ConnectionString">
<div class="form-group col-md-12">
<label asp-for="@Model.ConnectionString">@T["Connection string"]</label>
<input asp-for="@Model.ConnectionString" class="form-control" />
<span asp-validation-for="@Model.ConnectionString" class="text-danger"></span>
<span class="text-muted form-text small">@T["The connection string to your database instance. e.g., Data Source=<em>localhost</em>;Initial Catalog=<em>Orchard</em>;User Id=<em>userid</em>;Password=<em>password</em>"]</span>
</div>
</fieldset>
}
<h6>
@T["Super User"]
<span class="text-muted form-text small">@T["The super user has all the rights. It should be used only during Setup and for disaster recovery."]</span>
</h6>
<div class="row">
<div class="form-group col-md-6" asp-validation-class-for="@Model.UserName">
<label asp-for="@Model.UserName">@T["User name"]</label>
<input asp-for="@Model.UserName" class="form-control" />
<span asp-validation-for="@Model.UserName" class="text-danger">@T["The user name is required."]</span>
</div>
<div class="form-group col-md-6" asp-validation-class-for="@Model.Email">
<label for="Email">@T["Email"]</label>
<input asp-for="@Model.Email" class="form-control" type="email"/>
<span asp-validation-for="@Model.Email" class="text-danger">@T["The email is invalid."]</span>
</div>
</div>

<div class="row">
<div class="form-group col-md-6" asp-validation-class-for="@Model.Password">
<label asp-for="@Model.Password">@T["Password"]</label>
<input asp-for="@Model.Password" type="password" class="form-control" data-toggle="popover" data-placement="top" data-trigger="focus" title="@T["Password strength"]" data-content="@passwordTooltip" />
<div id="passwordStrength"></div>
<span asp-validation-for="@Model.Password" class="text-danger"></span>
</div>

<div class="form-group col-md-6" asp-validation-class-for="@Model.PasswordConfirmation">
<label asp-for="@Model.PasswordConfirmation">@T["Password Confirmation"]</label>
<input asp-for="@Model.PasswordConfirmation" type="password" class="form-control" />
<span asp-validation-for="@Model.PasswordConfirmation" class="text-danger"></span>
</div>
</div>
<fieldset>
<div class="form-group">
<button class="btn btn-primary" type="submit">@T["Finish Setup"]</button>
</div>
</fieldset>
</form>


<script src="/Orchard.Setup/Scripts/setup.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
$(function(){
$('#Password').strength({
minLength: @(options.Password.RequiredLength),
upperCase: @(options.Password.RequireUppercase ? "true" : "false"),
lowerCase: @(options.Password.RequireLowercase ? "true" : "false"),
numbers: @(options.Password.RequireDigit ? "true" : "false"),
specialchars: @(options.Password.RequireNonAlphanumeric ? "true" : "false"),
target: '#passwordStrength',
style: "margin-top: 7px; height: 7px; border-radius: 5px"
});
$('#Password').popover({
trigger: 'focus'
})
})
//]]>
</script>
Loading