mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
- Creation of the superuser, site settings and database during setup.
--HG-- branch : dev
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
using System.Web.Mvc;
|
using System;
|
||||||
|
using System.Web.Mvc;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Settings.Models;
|
||||||
using Orchard.Data.Migrations;
|
using Orchard.Data.Migrations;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Security;
|
||||||
using Orchard.Setup.ViewModels;
|
using Orchard.Setup.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
@@ -31,36 +35,55 @@ namespace Orchard.Setup.Controllers {
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Index(SetupViewModel model) {
|
public ActionResult Index(SetupViewModel model) {
|
||||||
TryUpdateModel(model);
|
try {
|
||||||
|
if (!ModelState.IsValid) {
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
// initialize the database:
|
||||||
return View(model);
|
// provider: SqlServer or SQLite
|
||||||
|
// dataFolder: physical path (map before calling). Builtin database will be created in this location
|
||||||
|
// connectionString: optional - if provided the dataFolder is essentially ignored, but should still be passed in
|
||||||
|
_databaseMigrationManager.CreateCoordinator(model.DatabaseOptions ? "SQLite" : "SqlServer", Server.MapPath("~/App_Data"), model.DatabaseConnectionString);
|
||||||
|
|
||||||
|
// creating a standalone environment.
|
||||||
|
// in theory this environment can be used to resolve any normal components by interface, and those
|
||||||
|
// components will exist entirely in isolation - no crossover between the safemode container currently in effect
|
||||||
|
var shellSettings = new ShellSettings { Name = "temp" };
|
||||||
|
using (var finiteEnvironment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) {
|
||||||
|
var contentManager = finiteEnvironment.Resolve<IContentManager>();
|
||||||
|
// create superuser
|
||||||
|
var membershipService = finiteEnvironment.Resolve<IMembershipService>();
|
||||||
|
var user = membershipService.CreateUser(new CreateUserParams(model.AdminUsername, model.AdminPassword, String.Empty, String.Empty, String.Empty, true));
|
||||||
|
|
||||||
|
// set site name and settings
|
||||||
|
contentManager.Create<SiteSettings>("site", item => {
|
||||||
|
item.Record.SiteSalt = Guid.NewGuid().ToString("N");
|
||||||
|
item.Record.SiteName = model.SiteName;
|
||||||
|
item.Record.SuperUser = model.AdminUsername;
|
||||||
|
item.Record.PageTitleSeparator = " - ";
|
||||||
|
});
|
||||||
|
|
||||||
|
// create home page as a CMS page
|
||||||
|
var page = contentManager.Create("page");
|
||||||
|
page.As<BodyAspect>().Text = "Welcome to Orchard";
|
||||||
|
page.As<RoutableAspect>().Slug = "home";
|
||||||
|
page.As<RoutableAspect>().Title = model.SiteName;
|
||||||
|
contentManager.Publish(page);
|
||||||
|
|
||||||
|
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
|
||||||
|
authenticationService.SignIn(user, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
_notifier.Information(T("Setup succeeded"));
|
||||||
|
|
||||||
|
// redirect to the welcome page.
|
||||||
|
return Redirect("~/home");
|
||||||
}
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
//notes: service call to initialize database:
|
_notifier.Error(T("Setup failed: " + exception.Message));
|
||||||
//_databaseMigrationManager.CreateCoordinator(provider, dataFolder, connectionString);
|
return RedirectToAction("Index");
|
||||||
// provider: SqlServer or SQLite
|
|
||||||
// dataFolder: physical path (map before calling). Builtin database will be created in this location
|
|
||||||
// connectionString: optional - if provided the dataFolder is essentially ignored, but should still be passed in
|
|
||||||
|
|
||||||
|
|
||||||
//notes: the other tool needed will be creating a standalone environment.
|
|
||||||
// in theory this environment can be used to resolve any normal components by interface, and those
|
|
||||||
// components will exist entirely in isolation - no crossover between the safemode container currently in effect
|
|
||||||
var shellSettings = new ShellSettings { Name = "temp" };
|
|
||||||
using (var finiteEnvironment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) {
|
|
||||||
var contentManager = finiteEnvironment.Resolve<IContentManager>();
|
|
||||||
var yadda = contentManager.Create("yadda");
|
|
||||||
|
|
||||||
// create superuser
|
|
||||||
// set site name
|
|
||||||
// database
|
|
||||||
// redirect to the welcome page
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_notifier.Information(T("Setup succeeded"));
|
|
||||||
return RedirectToAction("Index");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -79,6 +79,10 @@
|
|||||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||||
<Name>Orchard</Name>
|
<Name>Orchard</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
|
||||||
|
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||||
|
<Name>Orchard.Core</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
|
@@ -8,9 +8,10 @@ namespace Orchard.Setup.ViewModels {
|
|||||||
public string SiteName { get; set; }
|
public string SiteName { get; set; }
|
||||||
[StringLengthMin(3), StringLength(25)]
|
[StringLengthMin(3), StringLength(25)]
|
||||||
public string AdminUsername { get; set; }
|
public string AdminUsername { get; set; }
|
||||||
[StringLengthMin(6), StringLength(20)]
|
[Required, StringLengthMin(6), StringLength(20)]
|
||||||
public string AdminPassword { get; set; }
|
public string AdminPassword { get; set; }
|
||||||
[SqlDatabaseConnectionString]
|
[SqlDatabaseConnectionString]
|
||||||
public string DatabaseConnectionString { get; set; }
|
public string DatabaseConnectionString { get; set; }
|
||||||
|
public bool DatabaseOptions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -22,11 +22,11 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<%=Html.ValidationMessage("DatabaseOptions", "Unable to setup data storage") %>
|
<%=Html.ValidationMessage("DatabaseOptions", "Unable to setup data storage") %>
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" name="databaseOption" id="builtin" value="true" checked="checked" />
|
<input type="radio" name="databaseOptions" id="builtin" value="true" checked="checked" />
|
||||||
<label for="builtin"><%=_Encoded("Use built-in data storage (SQL Lite)") %></label>
|
<label for="builtin"><%=_Encoded("Use built-in data storage (SQL Lite)") %></label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" name="databaseOption" id="sql" value="false" />
|
<input type="radio" name="databaseOptions" id="sql" value="false" />
|
||||||
<label for="sql"><%=_Encoded("Use an existing SQL Server (or SQL Express) database") %></label>
|
<label for="sql"><%=_Encoded("Use an existing SQL Server (or SQL Express) database") %></label>
|
||||||
<!-- Should add some javascript to hide the connection string field if that option isn't selected -->
|
<!-- Should add some javascript to hide the connection string field if that option isn't selected -->
|
||||||
<label for="connection"><%=_Encoded("Connection string") %></label>
|
<label for="connection"><%=_Encoded("Connection string") %></label>
|
||||||
|
Reference in New Issue
Block a user