Files
Orchard/src/Orchard.Web/Modules/Orchard.DesignerTools/Controllers/AlternateController.cs
Sebastien Ros 52d5a2695c #17765: Fixing security notification in Shape Tracing
Work Items: 17765

--HG--
branch : 1.x
2011-05-09 13:37:25 -07:00

50 lines
1.9 KiB
C#

using System.IO;
using System.Web.Mvc;
using Orchard.FileSystems.WebSite;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Mvc.Extensions;
using Orchard.Themes;
namespace Orchard.DesignerTools.Controllers
{
[Themed]
public class AlternateController : Controller {
private readonly IWebSiteFolder _webSiteFolder;
private readonly IThemeManager _themeManager;
public AlternateController(IOrchardServices orchardServices, IWebSiteFolder webSiteFolder, IThemeManager themeManager) {
_webSiteFolder = webSiteFolder;
_themeManager = themeManager;
Services = orchardServices;
}
public IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public ActionResult Create(string template, string alternate, string returnUrl) {
if (!Request.IsLocal && !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to create templates")))
return new HttpUnauthorizedResult();
alternate = alternate.Replace("__", "-").Replace("_", ".");
var currentTheme = _themeManager.GetRequestTheme(Request.RequestContext);
var alternateFilename = Server.MapPath(Path.Combine(currentTheme.Location, currentTheme.Id, "Views", alternate));
// use same extension as template, or ".cshtml" if it's a code template))
if (_webSiteFolder.FileExists(template)) {
alternateFilename += Path.GetExtension(template);
using (var stream = System.IO.File.Create(alternateFilename)) {
_webSiteFolder.CopyFileTo(template, stream);
}
}
else {
alternateFilename += ".cshtml";
using (System.IO.File.Create(alternateFilename)) {}
}
return this.RedirectLocal(returnUrl);
}
}
}