--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-12-09 12:15:00 -08:00
19 changed files with 128 additions and 94 deletions

View File

@@ -58,16 +58,14 @@ namespace Orchard.Tests.Modules.CodeGeneration.Commands {
} }
[Test] [Test]
[ExpectedException(typeof(OrchardException))]
public void CreateDataMigrationTestNonExistentFeature() { public void CreateDataMigrationTestNonExistentFeature() {
CodeGenerationCommands codeGenerationCommands = new CodeGenerationCommands(_extensionManager, CodeGenerationCommands codeGenerationCommands = new CodeGenerationCommands(_extensionManager,
_schemaCommandGenerator); _schemaCommandGenerator);
TextWriter textWriterOutput = new StringWriter(); TextWriter textWriterOutput = new StringWriter();
codeGenerationCommands.Context = new CommandContext { Output = textWriterOutput }; codeGenerationCommands.Context = new CommandContext { Output = textWriterOutput };
bool result = codeGenerationCommands.CreateDataMigration("feature"); codeGenerationCommands.CreateDataMigration("feature");
Assert.That(result, Is.False);
Assert.That(textWriterOutput.ToString(), Is.EqualTo("Creating Data Migration for feature\r\nCreating data migration failed: target Feature feature could not be found.\r\n"));
} }
} }
} }

View File

@@ -0,0 +1,30 @@
using System;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Security;
using Orchard.Tasks.Scheduling;
namespace Orchard.Core.Common.Scheduling {
public abstract class OwnedScheduledTaskHandler : IScheduledTaskHandler {
private readonly IOrchardServices _orchardServices;
protected OwnedScheduledTaskHandler(IOrchardServices orchardServices) {
_orchardServices = orchardServices;
}
protected void SetCurrentUser(ContentItem contentItem) {
IUser owner = null;
var commonPart = contentItem.As<CommonPart>();
if (commonPart != null) {
owner = commonPart.Owner;
}
if (owner == null) {
var superUser = _orchardServices.WorkContext.CurrentSite.SuperUser;
owner = _orchardServices.WorkContext.Resolve<IMembershipService>().GetUser(superUser);
}
_orchardServices.WorkContext.Resolve<IAuthenticationService>().SetAuthenticatedUserForRequest(owner);
}
public abstract void Process(ScheduledTaskContext context);
}
}

View File

@@ -227,6 +227,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Common\Module.txt" /> <Content Include="Common\Module.txt" />
<Compile Include="Common\Scheduling\OwnedScheduledTaskHandler.cs" />
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" /> <Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" />
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.cshtml" /> <Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.cshtml" />
<Content Include="Common\Views\Fields.Common.Text.cshtml" /> <Content Include="Common\Views\Fields.Common.Text.cshtml" />

View File

@@ -1,27 +1,29 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Core.Common.Scheduling;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Tasks.Scheduling; using Orchard.Tasks.Scheduling;
namespace Orchard.ArchiveLater.Handlers { namespace Orchard.ArchiveLater.Handlers {
[UsedImplicitly] [UsedImplicitly]
public class UnpublishingTaskHandler : IScheduledTaskHandler { public class UnpublishingTaskHandler : OwnedScheduledTaskHandler {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
public UnpublishingTaskHandler(IContentManager contentManager) { public UnpublishingTaskHandler(IContentManager contentManager, IOrchardServices orchardServices) : base(orchardServices) {
_contentManager = contentManager; _contentManager = contentManager;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
} }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public void Process(ScheduledTaskContext context) { public override void Process(ScheduledTaskContext context) {
if (context.Task.TaskType == "Unpublish") { if (context.Task.TaskType == "Unpublish") {
Logger.Information("Unpublishing item #{0} version {1} scheduled at {2} utc", Logger.Information("Unpublishing item #{0} version {1} scheduled at {2} utc",
context.Task.ContentItem.Id, context.Task.ContentItem.Id,
context.Task.ContentItem.Version, context.Task.ContentItem.Version,
context.Task.ScheduledUtc); context.Task.ScheduledUtc);
SetCurrentUser(context.Task.ContentItem);
_contentManager.Unpublish(context.Task.ContentItem); _contentManager.Unpublish(context.Task.ContentItem);
} }
} }

View File

@@ -53,12 +53,11 @@ namespace Orchard.Blogs.Commands {
var owner = _membershipService.GetUser(Owner); var owner = _membershipService.GetUser(Owner);
if ( owner == null ) { if ( owner == null ) {
Context.Output.WriteLine(); throw new OrchardException(T("Invalid username: {0}", Owner));
return T("Invalid username: {0}", Owner).Text;
} }
if(!IsSlugValid(Slug)) { if(!IsSlugValid(Slug)) {
return "Invalid Slug provided. Blog creation failed."; throw new OrchardException(T("Invalid Slug provided. Blog creation failed."));
} }
var blog = _contentManager.New("Blog"); var blog = _contentManager.New("Blog");
@@ -83,8 +82,7 @@ namespace Orchard.Blogs.Commands {
var owner = _membershipService.GetUser(Owner); var owner = _membershipService.GetUser(Owner);
if(owner == null) { if(owner == null) {
Context.Output.WriteLine(); throw new OrchardException(T("Invalid username: {0}", Owner));
return T("Invalid username: {0}", Owner).Text;
} }
XDocument doc; XDocument doc;
@@ -95,14 +93,13 @@ namespace Orchard.Blogs.Commands {
Context.Output.WriteLine("Found {0} items", doc.Descendants("item").Count()); Context.Output.WriteLine("Found {0} items", doc.Descendants("item").Count());
} }
catch ( Exception ex ) { catch ( Exception ex ) {
Context.Output.WriteLine(T("An error occured while loading the file: " + ex.Message)); throw new OrchardException(T("An error occured while loading the file: {0}", ex.Message));
return "Import terminated.";
} }
var blog = _blogService.Get(Slug); var blog = _blogService.Get(Slug);
if ( blog == null ) { if ( blog == null ) {
return "Blog not found at specified slug: " + Slug; throw new OrchardException(T("Blog not found at specified slug: {0}", Slug));
} }
foreach ( var item in doc.Descendants("item") ) { foreach ( var item in doc.Descendants("item") ) {
@@ -122,7 +119,6 @@ namespace Orchard.Blogs.Commands {
} }
} }
return "Import feed completed."; return "Import feed completed.";
} }

View File

@@ -48,15 +48,14 @@ namespace Orchard.CodeGeneration.Commands {
[CommandHelp("codegen datamigration <feature-name> \r\n\t" + "Create a new Data Migration class")] [CommandHelp("codegen datamigration <feature-name> \r\n\t" + "Create a new Data Migration class")]
[CommandName("codegen datamigration")] [CommandName("codegen datamigration")]
public bool CreateDataMigration(string featureName) { public void CreateDataMigration(string featureName) {
Context.Output.WriteLine(T("Creating Data Migration for {0}", featureName)); Context.Output.WriteLine(T("Creating Data Migration for {0}", featureName));
ExtensionDescriptor extensionDescriptor = _extensionManager.AvailableExtensions().FirstOrDefault(extension => DefaultExtensionTypes.IsModule(extension.ExtensionType) && ExtensionDescriptor extensionDescriptor = _extensionManager.AvailableExtensions().FirstOrDefault(extension => DefaultExtensionTypes.IsModule(extension.ExtensionType) &&
extension.Features.Any(feature => String.Equals(feature.Id, featureName, StringComparison.OrdinalIgnoreCase))); extension.Features.Any(feature => String.Equals(feature.Id, featureName, StringComparison.OrdinalIgnoreCase)));
if (extensionDescriptor == null) { if (extensionDescriptor == null) {
Context.Output.WriteLine(T("Creating data migration failed: target Feature {0} could not be found.", featureName)); throw new OrchardException(T("Creating data migration failed: target Feature {0} could not be found.", featureName));
return false;
} }
string dataMigrationFolderPath = HostingEnvironment.MapPath("~/Modules/" + extensionDescriptor.Id + "/"); string dataMigrationFolderPath = HostingEnvironment.MapPath("~/Modules/" + extensionDescriptor.Id + "/");
@@ -69,8 +68,7 @@ namespace Orchard.CodeGeneration.Commands {
} }
if (File.Exists(dataMigrationFilePath)) { if (File.Exists(dataMigrationFilePath)) {
Context.Output.WriteLine(T("Data migration already exists in target Module {0}.", extensionDescriptor.Id)); throw new OrchardException(T("Data migration already exists in target Module {0}.", extensionDescriptor.Id));
return false;
} }
List<SchemaCommand> commands = _schemaCommandGenerator.GetCreateFeatureCommands(featureName, false).ToList(); List<SchemaCommand> commands = _schemaCommandGenerator.GetCreateFeatureCommands(featureName, false).ToList();
@@ -104,25 +102,20 @@ namespace Orchard.CodeGeneration.Commands {
File.WriteAllText(moduleCsProjPath, projectFileText); File.WriteAllText(moduleCsProjPath, projectFileText);
TouchSolution(Context.Output); TouchSolution(Context.Output);
Context.Output.WriteLine(T("Data migration created successfully in Module {0}", extensionDescriptor.Id)); Context.Output.WriteLine(T("Data migration created successfully in Module {0}", extensionDescriptor.Id));
return true;
} }
[CommandHelp("codegen module <module-name> [/IncludeInSolution:true|false]\r\n\t" + "Create a new Orchard module")] [CommandHelp("codegen module <module-name> [/IncludeInSolution:true|false]\r\n\t" + "Create a new Orchard module")]
[CommandName("codegen module")] [CommandName("codegen module")]
[OrchardSwitches("IncludeInSolution")] [OrchardSwitches("IncludeInSolution")]
public bool CreateModule(string moduleName) { public void CreateModule(string moduleName) {
Context.Output.WriteLine(T("Creating Module {0}", moduleName)); Context.Output.WriteLine(T("Creating Module {0}", moduleName));
if ( _extensionManager.AvailableExtensions().Any(extension => String.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase)) ) { if ( _extensionManager.AvailableExtensions().Any(extension => String.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase)) ) {
Context.Output.WriteLine(T("Creating Module {0} failed: a module of the same name already exists", moduleName)); throw new OrchardException(T("Creating Module {0} failed: a module of the same name already exists", moduleName));
return false;
} }
IntegrateModule(moduleName); IntegrateModule(moduleName);
Context.Output.WriteLine(T("Module {0} created successfully", moduleName)); Context.Output.WriteLine(T("Module {0} created successfully", moduleName));
return true;
} }
[CommandName("codegen theme")] [CommandName("codegen theme")]
@@ -131,20 +124,18 @@ namespace Orchard.CodeGeneration.Commands {
public void CreateTheme(string themeName) { public void CreateTheme(string themeName) {
Context.Output.WriteLine(T("Creating Theme {0}", themeName)); Context.Output.WriteLine(T("Creating Theme {0}", themeName));
if (_extensionManager.AvailableExtensions().Any(extension => String.Equals(themeName, extension.Id, StringComparison.OrdinalIgnoreCase))) { if (_extensionManager.AvailableExtensions().Any(extension => String.Equals(themeName, extension.Id, StringComparison.OrdinalIgnoreCase))) {
Context.Output.WriteLine(T("Creating Theme {0} failed: an extention of the same name already exists", themeName)); throw new OrchardException(T("Creating Theme {0} failed: an extention of the same name already exists", themeName));
} }
else {
if (!string.IsNullOrEmpty(BasedOn)) { if (!string.IsNullOrEmpty(BasedOn)) {
if (!_extensionManager.AvailableExtensions().Any(extension => if (!_extensionManager.AvailableExtensions().Any(extension =>
string.Equals(extension.ExtensionType, DefaultExtensionTypes.Theme, StringComparison.OrdinalIgnoreCase) && string.Equals(extension.ExtensionType, DefaultExtensionTypes.Theme, StringComparison.OrdinalIgnoreCase) &&
string.Equals(BasedOn, extension.Id, StringComparison.OrdinalIgnoreCase))) { string.Equals(BasedOn, extension.Id, StringComparison.OrdinalIgnoreCase))) {
Context.Output.WriteLine(T("Creating Theme {0} failed: base theme named {1} was not found.", themeName, BasedOn)); throw new OrchardException(T("Creating Theme {0} failed: base theme named {1} was not found.", themeName, BasedOn));
return;
}
} }
IntegrateTheme(themeName, BasedOn);
Context.Output.WriteLine(T("Theme {0} created successfully", themeName));
} }
IntegrateTheme(themeName, BasedOn);
Context.Output.WriteLine(T("Theme {0} created successfully", themeName));
} }
[CommandHelp("codegen controller <module-name> <controller-name>\r\n\t" + "Create a new Orchard controller in a module")] [CommandHelp("codegen controller <module-name> <controller-name>\r\n\t" + "Create a new Orchard controller in a module")]
@@ -156,8 +147,7 @@ namespace Orchard.CodeGeneration.Commands {
string.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase)); string.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase));
if (extensionDescriptor == null) { if (extensionDescriptor == null) {
Context.Output.WriteLine(T("Creating Controller {0} failed: target Module {1} could not be found.", controllerName, moduleName)); throw new OrchardException(T("Creating Controller {0} failed: target Module {1} could not be found.", controllerName, moduleName));
return;
} }
string moduleControllersPath = HostingEnvironment.MapPath("~/Modules/" + extensionDescriptor.Id + "/Controllers/"); string moduleControllersPath = HostingEnvironment.MapPath("~/Modules/" + extensionDescriptor.Id + "/Controllers/");
@@ -169,8 +159,7 @@ namespace Orchard.CodeGeneration.Commands {
Directory.CreateDirectory(moduleControllersPath); Directory.CreateDirectory(moduleControllersPath);
} }
if (File.Exists(controllerPath)) { if (File.Exists(controllerPath)) {
Context.Output.WriteLine(T("Controller {0} already exists in target Module {1}.", controllerName, moduleName)); throw new OrchardException(T("Controller {0} already exists in target Module {1}.", controllerName, moduleName));
return;
} }
string controllerText = File.ReadAllText(templatesPath + "Controller.txt"); string controllerText = File.ReadAllText(templatesPath + "Controller.txt");

View File

@@ -26,13 +26,17 @@ namespace Orchard.Comments {
Name = "Anonymous", Name = "Anonymous",
Permissions = new[] {AddComment} Permissions = new[] {AddComment}
}, },
new PermissionStereotype {
Name = "Authenticated",
Permissions = new[] {AddComment}
},
new PermissionStereotype { new PermissionStereotype {
Name = "Editor", Name = "Editor",
Permissions = new[] {AddComment} Permissions = new[] {AddComment}
}, },
new PermissionStereotype { new PermissionStereotype {
Name = "Moderator", Name = "Moderator",
Permissions = new[] {AddComment} Permissions = new[] {ManageComments, AddComment}
}, },
new PermissionStereotype { new PermissionStereotype {
Name = "Author", Name = "Author",

View File

@@ -69,7 +69,7 @@ namespace Orchard.Experimental.Commands {
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
var user = _membershipService.CreateUser(new CreateUserParams("user" + i, "1234567", "user" + i + "@orchardproject.net", null, null, true)); var user = _membershipService.CreateUser(new CreateUserParams("user" + i, "1234567", "user" + i + "@orchardproject.net", null, null, true));
if (user == null) if (user == null)
return "The authentication provider returned an error"; throw new OrchardException(T("The authentication provider returned an error"));
} }
return "Success"; return "Success";

View File

@@ -38,7 +38,7 @@ namespace Orchard.Indexing.Commands {
[OrchardSwitches("IndexName")] [OrchardSwitches("IndexName")]
public string Update() { public string Update() {
if ( !_indexManager.HasIndexProvider() ) { if ( !_indexManager.HasIndexProvider() ) {
return "No index available"; throw new OrchardException(T("No index available"));
} }
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName;
@@ -54,7 +54,7 @@ namespace Orchard.Indexing.Commands {
[OrchardSwitches("IndexName")] [OrchardSwitches("IndexName")]
public string Rebuild() { public string Rebuild() {
if ( !_indexManager.HasIndexProvider() ) { if ( !_indexManager.HasIndexProvider() ) {
return "No index available"; throw new OrchardException(T("No index available"));
} }
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName;
@@ -71,7 +71,7 @@ namespace Orchard.Indexing.Commands {
[OrchardSwitches("Query,IndexName")] [OrchardSwitches("Query,IndexName")]
public string Search() { public string Search() {
if ( !_indexManager.HasIndexProvider() ) { if ( !_indexManager.HasIndexProvider() ) {
return "No index available"; throw new OrchardException(T("No index available"));
} }
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName;
var searchBuilder = _indexManager.GetSearchIndexProvider().CreateSearchBuilder(indexName); var searchBuilder = _indexManager.GetSearchIndexProvider().CreateSearchBuilder(indexName);
@@ -99,7 +99,7 @@ namespace Orchard.Indexing.Commands {
[OrchardSwitches("IndexName")] [OrchardSwitches("IndexName")]
public string Stats() { public string Stats() {
if ( !_indexManager.HasIndexProvider() ) { if ( !_indexManager.HasIndexProvider() ) {
return "No index available"; throw new OrchardException(T("No index available"));
} }
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName;
Context.Output.WriteLine("Number of indexed documents: {0}", _indexManager.GetSearchIndexProvider().NumDocs(indexName)); Context.Output.WriteLine("Number of indexed documents: {0}", _indexManager.GetSearchIndexProvider().NumDocs(indexName));
@@ -112,7 +112,7 @@ namespace Orchard.Indexing.Commands {
public string Refresh() { public string Refresh() {
int contentItemId; int contentItemId;
if ( !int.TryParse(ContentItemId, out contentItemId) ) { if ( !int.TryParse(ContentItemId, out contentItemId) ) {
return "Invalid content item id. Not an integer."; throw new OrchardException(T("Invalid content item id. Not an integer."));
} }
var contentItem = _contentManager.Get(contentItemId); var contentItem = _contentManager.Get(contentItemId);
@@ -127,7 +127,7 @@ namespace Orchard.Indexing.Commands {
public string Delete() { public string Delete() {
int contenItemId; int contenItemId;
if(!int.TryParse(ContentItemId, out contenItemId)) { if(!int.TryParse(ContentItemId, out contenItemId)) {
return "Invalid content item id. Not an integer."; throw new OrchardException(T("Invalid content item id. Not an integer."));
} }
var contentItem = _contentManager.Get(contenItemId); var contentItem = _contentManager.Get(contenItemId);

View File

@@ -3,7 +3,7 @@
<h1>@Html.TitleForPage(T("Manage Media Folders").ToString())</h1> <h1>@Html.TitleForPage(T("Manage Media Folders").ToString())</h1>
@Html.ValidationSummary() @Html.ValidationSummary()
@using (Html.BeginFormAntiForgeryPost()) {
<fieldset class="bulk-actions"> <fieldset class="bulk-actions">
<label for="publishActions">@T("Actions:")</label> <label for="publishActions">@T("Actions:")</label>
<select id="Select1" name="publishActions"> <select id="Select1" name="publishActions">
@@ -50,3 +50,4 @@
} }
</table> </table>
</fieldset> </fieldset>
}

View File

@@ -28,8 +28,7 @@ namespace Orchard.Packaging.Commands {
public void CreatePackage(string extensionName, string path) { public void CreatePackage(string extensionName, string path) {
var packageData = _packageManager.Harvest(extensionName); var packageData = _packageManager.Harvest(extensionName);
if (packageData == null) { if (packageData == null) {
Context.Output.WriteLine(T("Module or Theme \"{0}\" does not exist in this Orchard installation.", extensionName)); throw new OrchardException(T("Module or Theme \"{0}\" does not exist in this Orchard installation.", extensionName));
return;
} }
// append "Orchard.[ExtensionType]" to prevent conflicts with other packages (e.g, TinyMce, jQuery, ...) // append "Orchard.[ExtensionType]" to prevent conflicts with other packages (e.g, TinyMce, jQuery, ...)
@@ -79,7 +78,7 @@ namespace Orchard.Packaging.Commands {
} }
catch(Exception e) { catch(Exception e) {
// Exceptions area thrown by NuGet as error messages // Exceptions area thrown by NuGet as error messages
Context.Output.WriteLine(HttpUtility.HtmlDecode(T("Could not unintall the package: {0}", e.Message).Text)); throw new OrchardException(T(HttpUtility.HtmlDecode(T("Could not unintall the package: {0}", e.Message).Text)));
} }
} }

View File

@@ -1,27 +1,29 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Core.Common.Scheduling;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Tasks.Scheduling; using Orchard.Tasks.Scheduling;
namespace Orchard.PublishLater.Handlers { namespace Orchard.PublishLater.Handlers {
[UsedImplicitly] [UsedImplicitly]
public class PublishingTaskHandler : IScheduledTaskHandler { public class PublishingTaskHandler : OwnedScheduledTaskHandler {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
public PublishingTaskHandler(IContentManager contentManager) { public PublishingTaskHandler(IContentManager contentManager, IOrchardServices orchardServices) : base(orchardServices) {
_contentManager = contentManager; _contentManager = contentManager;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
} }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public void Process(ScheduledTaskContext context) { public override void Process(ScheduledTaskContext context) {
if (context.Task.TaskType == "Publish") { if (context.Task.TaskType == "Publish") {
Logger.Information("Publishing item #{0} version {1} scheduled at {2} utc", Logger.Information("Publishing item #{0} version {1} scheduled at {2} utc",
context.Task.ContentItem.Id, context.Task.ContentItem.Id,
context.Task.ContentItem.Version, context.Task.ContentItem.Version,
context.Task.ScheduledUtc); context.Task.ScheduledUtc);
SetCurrentUser(context.Task.ContentItem);
_contentManager.Publish(context.Task.ContentItem); _contentManager.Publish(context.Task.ContentItem);
} }
} }

View File

@@ -30,19 +30,20 @@ namespace Orchard.Users.Commands {
[CommandHelp("user create /UserName:<username> /Password:<password> /Email:<email>\r\n\t" + "Creates a new User")] [CommandHelp("user create /UserName:<username> /Password:<password> /Email:<email>\r\n\t" + "Creates a new User")]
[OrchardSwitches("UserName,Password,Email")] [OrchardSwitches("UserName,Password,Email")]
public string Create() { public string Create() {
string userUnicityMessage = _userService.VerifyUserUnicity(UserName, Email); if (!_userService.VerifyUserUnicity(UserName, Email)) {
if (userUnicityMessage != null) { throw new OrchardException(T("User with that username and/or email already exists."));
return userUnicityMessage;
} }
if (Password == null || Password.Length < MinPasswordLength) { if (Password == null || Password.Length < MinPasswordLength) {
return T("You must specify a password of {0} or more characters.", MinPasswordLength).ToString(); throw new OrchardException(T("You must specify a password of {0} or more characters.", MinPasswordLength));
} }
var user = _membershipService.CreateUser(new CreateUserParams(UserName, Password, Email, null, null, true)); var user = _membershipService.CreateUser(new CreateUserParams(UserName, Password, Email, null, null, true));
if (user != null) if (user == null) {
return T("User created successfully").ToString(); throw new OrchardException(T("The authentication provider returned an error"));
}
return T("The authentication provider returned an error").ToString(); return T("User created successfully").ToString();
} }
int MinPasswordLength { int MinPasswordLength {

View File

@@ -333,9 +333,8 @@ namespace Orchard.Users.Controllers {
if (!validate) if (!validate)
return false; return false;
string userUnicityMessage = _userService.VerifyUserUnicity(userName, email); if (!_userService.VerifyUserUnicity(userName, email)) {
if (userUnicityMessage != null) { ModelState.AddModelError("userExists", T("User with that username and/or email already exists."));
ModelState.AddModelError("userExists", T(userUnicityMessage));
} }
if (password == null || password.Length < MinPasswordLength) { if (password == null || password.Length < MinPasswordLength) {
ModelState.AddModelError("password", T("You must specify a password of {0} or more characters.", MinPasswordLength)); ModelState.AddModelError("password", T("You must specify a password of {0} or more characters.", MinPasswordLength));

View File

@@ -77,9 +77,8 @@ namespace Orchard.Users.Controllers {
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
if (!string.IsNullOrEmpty(createModel.UserName)) { if (!string.IsNullOrEmpty(createModel.UserName)) {
string userExistsMessage = _userService.VerifyUserUnicity(createModel.UserName, createModel.Email); if (!_userService.VerifyUserUnicity(createModel.UserName, createModel.Email)) {
if (userExistsMessage != null) { AddModelError("NotUniqueUserName", T("User with that username and/or email already exists."));
AddModelError("NotUniqueUserName", T(userExistsMessage));
} }
} }
@@ -139,9 +138,8 @@ namespace Orchard.Users.Controllers {
var editModel = new UserEditViewModel {User = user}; var editModel = new UserEditViewModel {User = user};
if (TryUpdateModel(editModel)) { if (TryUpdateModel(editModel)) {
string userExistsMessage = _userService.VerifyUserUnicity(id, editModel.UserName, editModel.Email); if (!_userService.VerifyUserUnicity(id, editModel.UserName, editModel.Email)) {
if (userExistsMessage != null) { AddModelError("NotUniqueUserName", T("User with that username and/or email already exists."));
AddModelError("NotUniqueUserName", T(userExistsMessage));
} }
else { else {
// also update the Super user if this is the renamed account // also update the Super user if this is the renamed account

View File

@@ -2,8 +2,8 @@ using Orchard.Security;
using System; using System;
namespace Orchard.Users.Services { namespace Orchard.Users.Services {
public interface IUserService : IDependency { public interface IUserService : IDependency {
string VerifyUserUnicity(string userName, string email); bool VerifyUserUnicity(string userName, string email);
string VerifyUserUnicity(int id, string userName, string email); bool VerifyUserUnicity(int id, string userName, string email);
void SendChallengeEmail(IUser user, Func<string, string> createUrl); void SendChallengeEmail(IUser user, Func<string, string> createUrl);
IUser ValidateChallenge(string challengeToken); IUser ValidateChallenge(string challengeToken);

View File

@@ -36,7 +36,7 @@ namespace Orchard.Users.Services {
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public string VerifyUserUnicity(string userName, string email) { public bool VerifyUserUnicity(string userName, string email) {
string normalizedUserName = userName.ToLower(); string normalizedUserName = userName.ToLower();
if (_contentManager.Query<UserPart, UserPartRecord>() if (_contentManager.Query<UserPart, UserPartRecord>()
@@ -44,13 +44,13 @@ namespace Orchard.Users.Services {
user.NormalizedUserName == normalizedUserName || user.NormalizedUserName == normalizedUserName ||
user.Email == email) user.Email == email)
.List().Any()) { .List().Any()) {
return "User with that username and/or email already exists."; return false;
} }
return null; return true;
} }
public string VerifyUserUnicity(int id, string userName, string email) { public bool VerifyUserUnicity(int id, string userName, string email) {
string normalizedUserName = userName.ToLower(); string normalizedUserName = userName.ToLower();
if (_contentManager.Query<UserPart, UserPartRecord>() if (_contentManager.Query<UserPart, UserPartRecord>()
@@ -58,10 +58,10 @@ namespace Orchard.Users.Services {
user.NormalizedUserName == normalizedUserName || user.NormalizedUserName == normalizedUserName ||
user.Email == email) user.Email == email)
.List().Any(user => user.Id != id)) { .List().Any(user => user.Id != id)) {
return "User with that username and/or email already exists."; return false;
} }
return null; return true;
} }
public string CreateNonce(IUser user, TimeSpan delay) { public string CreateNonce(IUser user, TimeSpan delay) {

View File

@@ -43,7 +43,7 @@ namespace Orchard.Widgets.Services {
public IEnumerable<string> GetZones() { public IEnumerable<string> GetZones() {
return _featureManager.GetEnabledFeatures() return _featureManager.GetEnabledFeatures()
.Select(x => x.Extension) .Select(x => x.Extension)
.Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType)) .Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType) && x.Zones != null)
.SelectMany(x => x.Zones.Split(',')) .SelectMany(x => x.Zones.Split(','))
.Distinct() .Distinct()
.Select(x => x.Trim()) .Select(x => x.Trim())

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Routing; using System.Web.Routing;
using Autofac; using Autofac;
@@ -99,6 +100,12 @@ namespace Orchard.Commands {
return CommandReturnCodes.Retry; return CommandReturnCodes.Retry;
} }
catch (Exception e) { catch (Exception e) {
if (e is TargetInvocationException &&
e.InnerException != null) {
// If this is an exception coming from reflection and there is an innerexception which is the actual one, redirect
e = e.InnerException;
}
OutputException(output, T("Error executing command \"{0}\"", string.Join(" ", args)), e); OutputException(output, T("Error executing command \"{0}\"", string.Join(" ", args)), e);
return CommandReturnCodes.Fail; return CommandReturnCodes.Fail;
} }
@@ -138,7 +145,6 @@ namespace Orchard.Commands {
// Display header // Display header
output.WriteLine(); output.WriteLine();
output.WriteLine(T("{0}", title)); output.WriteLine(T("{0}", title));
output.WriteLine(T("--------------------------------------------------------------------------------"));
// Push exceptions in a stack so we display from inner most to outer most // Push exceptions in a stack so we display from inner most to outer most
var errors = new Stack<Exception>(); var errors = new Stack<Exception>();
@@ -148,18 +154,26 @@ namespace Orchard.Commands {
// Display inner most exception details // Display inner most exception details
exception = errors.Peek(); exception = errors.Peek();
output.WriteLine(T("--------------------------------------------------------------------------------"));
output.WriteLine();
output.WriteLine(T("{0}", exception.Message)); output.WriteLine(T("{0}", exception.Message));
output.WriteLine(); output.WriteLine();
output.WriteLine(T("Exception Details: {0}: {1}", exception.GetType().FullName, exception.Message));
output.WriteLine();
output.WriteLine(T("Stack Trace:"));
output.WriteLine();
// Display exceptions from inner most to outer most if (!((exception is OrchardException ||
foreach(var error in errors) { exception is OrchardCoreException) &&
output.WriteLine(T("[{0}: {1}]", error.GetType().Name, error.Message)); exception.InnerException == null)) {
output.WriteLine(T("{0}", error.StackTrace));
output.WriteLine(T("Exception Details: {0}: {1}", exception.GetType().FullName, exception.Message));
output.WriteLine(); output.WriteLine();
output.WriteLine(T("Stack Trace:"));
output.WriteLine();
// Display exceptions from inner most to outer most
foreach (var error in errors) {
output.WriteLine(T("[{0}: {1}]", error.GetType().Name, error.Message));
output.WriteLine(T("{0}", error.StackTrace));
output.WriteLine();
}
} }
// Display footer // Display footer