Added super user password fields to UploadRecipe import action.

This commit is contained in:
Sipke Schoorstra
2015-07-16 10:52:02 +01:00
parent 405ed7452a
commit dbe7e30f80
3 changed files with 28 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
@@ -35,13 +36,16 @@ namespace Orchard.ImportExport.Providers.ImportActions {
public HttpPostedFileBase File { get; set; }
public bool ResetSite { get; set; }
public string SuperUserPassword { get; set; }
public override dynamic BuildEditor(dynamic shapeFactory) {
return UpdateEditor(shapeFactory, null);
}
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
var viewModel = new UploadRecipeViewModel();
var viewModel = new UploadRecipeViewModel {
SuperUserName = _orchardServices.WorkContext.CurrentSite.SuperUser
};
if (updater != null) {
@@ -50,9 +54,17 @@ namespace Orchard.ImportExport.Providers.ImportActions {
File = request.Files["RecipeFile"];
ResetSite = viewModel.ResetSite;
SuperUserPassword = viewModel.SuperUserPassword;
if (File == null || File.ContentLength == 0)
updater.AddModelError("RecipeFile", T("No recipe file selected."));
if (ResetSite) {
if(String.IsNullOrWhiteSpace(viewModel.SuperUserPassword))
updater.AddModelError("SuperUserPassword", T("Please specify a new password for the super user."));
else if(!String.Equals(viewModel.SuperUserPassword, viewModel.SuperUserPasswordConfirmation))
updater.AddModelError("SuperUserPassword", T("The passwords do not match."));
}
}
}
@@ -71,7 +83,7 @@ namespace Orchard.ImportExport.Providers.ImportActions {
var setupContext = new SetupContext {
DropExistingTables = true,
RecipeText = ReadRecipeFile(),
AdminPassword = "password",
AdminPassword = SuperUserPassword,
AdminUsername = _orchardServices.WorkContext.CurrentSite.SuperUser,
DatabaseConnectionString = _shellSettings.DataConnectionString,
DatabaseProvider = _shellSettings.DataProvider,

View File

@@ -1,5 +1,8 @@
namespace Orchard.ImportExport.ViewModels {
public class UploadRecipeViewModel {
public bool ResetSite { get; set; }
public string SuperUserName { get; set; }
public string SuperUserPassword { get; set; }
public string SuperUserPasswordConfirmation { get; set; }
}
}

View File

@@ -13,6 +13,16 @@
@Html.Hint(T("Check this option to reset your site before executing the uploaded recipe."))
</div>
<div data-controllerid="@Html.FieldIdFor(m => m.ResetSite)">
<div>
@Html.LabelFor(m => m.SuperUserPassword, T("Super User Password"))
@Html.PasswordFor(m => m.SuperUserPassword, new {@class = "text medium"})
@Html.Hint(T("Specify a new password for the super user in case your recipe doesn't contain the current super user."))
</div>
<div>
@Html.LabelFor(m => m.SuperUserPasswordConfirmation, T("Confirm Super User Password"))
@Html.PasswordFor(m => m.SuperUserPasswordConfirmation, new { @class = "text medium" })
@Html.Hint(T("Repeat the password to make sure you didn't mistype anything."))
</div>
<div class="message message-Warning">@T("This will delete your database tables. Please consider creating a backup first.")</div>
</div>
</fieldset>