--HG--
branch : theming
This commit is contained in:
Louis DeJardin 2010-09-14 13:17:24 -07:00
commit dacf985309
4 changed files with 130 additions and 8 deletions

View File

@ -1,10 +1,12 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using System.Xml.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Core.Feeds.Models;
using Orchard.Core.Feeds.StandardBuilders;
using Orchard.Utility.Extensions;
namespace Orchard.Core.Feeds.StandardQueries {
[UsedImplicitly]
@ -45,7 +47,8 @@ namespace Orchard.Core.Feeds.StandardQueries {
context.Response.Contextualize(requestContext => {
var urlHelper = new UrlHelper(requestContext);
link.Add(urlHelper.RouteUrl(inspector.Link));
var uriBuilder = new UriBuilder(urlHelper.RequestContext.HttpContext.Request.ToRootUrlString()) { Path = urlHelper.RouteUrl(inspector.Link) };
link.Add(uriBuilder.Uri.OriginalString);
});
}
else {

View File

@ -1,4 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Mvc;
@ -27,12 +27,9 @@ namespace Orchard.DevTools.Controllers {
[HttpPost]
public ActionResult Execute(CommandsExecuteViewModel model) {
var writer = new StringWriter();
var parameters = new CommandParameters {
Arguments = model.CommandLine.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
Output = writer
};
var commandLine = model.CommandLine.Trim();
CommandParameters parameters = GetCommandParameters(commandLine, writer);
_commandManager.Execute(parameters);
model.History = (model.History ?? Enumerable.Empty<string>())
@ -43,6 +40,63 @@ namespace Orchard.DevTools.Controllers {
return View("Execute", model);
}
private static CommandParameters GetCommandParameters(string commandLine, StringWriter writer) {
var arguments = new List<string>();
var switches = new Dictionary<string,string>();
var current = 0;
while (current < commandLine.Length) {
var nextSpace = commandLine.IndexOf(' ', current);
if (nextSpace == -1) nextSpace = commandLine.Length;
var arg = commandLine.Substring(current, nextSpace - current).Trim();
if (arg.Length == 0) {
current = nextSpace + 1;
continue;
}
if (arg[0] == '/') {
var colonIndex = arg.IndexOf(':');
if (colonIndex != -1) {
var switchName = arg.Substring(1, colonIndex - 1);
if (arg.Length > colonIndex + 1) {
if (arg[colonIndex + 1] == '"') {
var beginningOfSwitchValue = commandLine.IndexOf('"', current) + 1;
if (beginningOfSwitchValue != 0) {
var endOfSwitchValue = commandLine.IndexOf('"', beginningOfSwitchValue);
if (endOfSwitchValue != -1) {
switches.Add(switchName,
commandLine.Substring(beginningOfSwitchValue,
endOfSwitchValue - beginningOfSwitchValue));
current = endOfSwitchValue + 1;
continue;
}
}
}
else {
switches.Add(switchName, arg.Substring(colonIndex + 1));
current = nextSpace + 1;
continue;
}
}
}
}
else if (arg[0] == '"') {
var argumentStart = commandLine.IndexOf('"', current) + 1;
var argumentEnd = commandLine.IndexOf('"', argumentStart);
if (argumentEnd != -1) {
arguments.Add(commandLine.Substring(argumentStart, argumentEnd - argumentStart));
current = argumentEnd + 1;
continue;
}
}
arguments.Add(arg);
current = nextSpace + 1;
}
return new CommandParameters {
Arguments = arguments,
Switches = switches,
Output = writer
};
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Orchard.Commands;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Security;
using Orchard.Users.Services;
using System.Web.Security;
namespace Orchard.Users.Commands {
public class UserCommands : DefaultOrchardCommandHandler {
private readonly IContentManager _contentManager;
private readonly IMembershipService _membershipService;
private readonly IUserService _userService;
public UserCommands(
IContentManager contentManager,
IMembershipService membershipService,
IUserService userService) {
_contentManager = contentManager;
_membershipService = membershipService;
_userService = userService;
}
[OrchardSwitch]
public string UserName { get; set; }
[OrchardSwitch]
public string Password { get; set; }
[OrchardSwitch]
public string Email { get; set; }
[OrchardSwitch]
public string FileName { get; set; }
[CommandName("user create")]
[CommandHelp("user create /UserName:<username> /Password:<password> /Email:<email>\r\n\t" + "Creates a new User")]
[OrchardSwitches("UserName,Password,Email")]
public string Create() {
string userUnicityMessage = _userService.VerifyUserUnicity(UserName, Email);
if (userUnicityMessage != null) {
return userUnicityMessage;
}
if (Password == null || Password.Length < MinPasswordLength) {
return T("You must specify a password of {0} or more characters.", MinPasswordLength).ToString();
}
var user = _membershipService.CreateUser(new CreateUserParams(UserName, Password, Email, null, null, true));
if (user != null)
return T("User created successfully").ToString();
else
return T("The authentication provider returned an error").ToString();
}
int MinPasswordLength {
get {
return _membershipService.GetSettings().MinRequiredPasswordLength;
}
}
}
}

View File

@ -67,6 +67,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\UserCommands.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="DataMigrations\UsersDataMigration.cs" />