- Creation of the superuser, site settings and database during setup.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-02-08 14:18:28 -08:00
parent 17d063fa21
commit 4d070d1ca7
4 changed files with 59 additions and 31 deletions

View File

@@ -1,8 +1,12 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Core.Settings.Models;
using Orchard.Data.Migrations;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Security;
using Orchard.Setup.ViewModels;
using Orchard.Localization;
using Orchard.UI.Notify;
@@ -31,36 +35,55 @@ namespace Orchard.Setup.Controllers {
[HttpPost]
public ActionResult Index(SetupViewModel model) {
TryUpdateModel(model);
try {
if (!ModelState.IsValid) {
return View(model);
}
//notes: service call to initialize database:
//_databaseMigrationManager.CreateCoordinator(provider, dataFolder, connectionString);
// initialize the database:
// 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);
//notes: the other tool needed will be creating a standalone environment.
// 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
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) {
_notifier.Error(T("Setup failed: " + exception.Message));
return RedirectToAction("Index");
}
}
}
}

View File

@@ -79,6 +79,10 @@
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard</Name>
</ProjectReference>
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Module.txt" />

View File

@@ -8,9 +8,10 @@ namespace Orchard.Setup.ViewModels {
public string SiteName { get; set; }
[StringLengthMin(3), StringLength(25)]
public string AdminUsername { get; set; }
[StringLengthMin(6), StringLength(20)]
[Required, StringLengthMin(6), StringLength(20)]
public string AdminPassword { get; set; }
[SqlDatabaseConnectionString]
public string DatabaseConnectionString { get; set; }
public bool DatabaseOptions { get; set; }
}
}

View File

@@ -22,11 +22,11 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<fieldset>
<%=Html.ValidationMessage("DatabaseOptions", "Unable to setup data storage") %>
<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>
</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>
<!-- Should add some javascript to hide the connection string field if that option isn't selected -->
<label for="connection"><%=_Encoded("Connection string") %></label>