2009-12-10 22:21:57 +00:00
|
|
|
|
using System;
|
2009-12-11 19:49:53 +00:00
|
|
|
|
using System.Web;
|
2009-12-10 22:21:57 +00:00
|
|
|
|
using System.Web.Mvc;
|
2009-12-10 00:15:58 +00:00
|
|
|
|
using Orchard.Core.Themes.ViewModels;
|
|
|
|
|
|
using Orchard.Localization;
|
2009-12-11 20:02:51 +00:00
|
|
|
|
using Orchard.Security;
|
2009-12-10 00:15:58 +00:00
|
|
|
|
using Orchard.Themes;
|
|
|
|
|
|
using Orchard.UI.Notify;
|
2009-12-11 00:40:44 +00:00
|
|
|
|
using Orchard.Mvc.ViewModels;
|
2009-12-10 00:15:58 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Themes.Controllers {
|
|
|
|
|
|
[ValidateInput(false)]
|
|
|
|
|
|
public class AdminController : Controller {
|
|
|
|
|
|
private readonly IThemeService _themeService;
|
2009-12-11 20:02:51 +00:00
|
|
|
|
private readonly IAuthorizer _authorizer;
|
2009-12-10 00:15:58 +00:00
|
|
|
|
private readonly INotifier _notifier;
|
|
|
|
|
|
|
2009-12-11 20:02:51 +00:00
|
|
|
|
public AdminController(IThemeService themeService, IAuthorizer authorizer, INotifier notifier) {
|
2009-12-10 00:15:58 +00:00
|
|
|
|
_themeService = themeService;
|
2009-12-11 20:02:51 +00:00
|
|
|
|
_authorizer = authorizer;
|
2009-12-10 00:15:58 +00:00
|
|
|
|
_notifier = notifier;
|
|
|
|
|
|
T = NullLocalizer.Instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ActionResult Index() {
|
2009-12-10 22:21:57 +00:00
|
|
|
|
try {
|
|
|
|
|
|
var themes = _themeService.GetInstalledThemes();
|
2009-12-15 19:50:37 +00:00
|
|
|
|
var currentTheme = _themeService.GetSiteTheme();
|
2009-12-10 22:21:57 +00:00
|
|
|
|
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
|
|
|
|
|
|
return View(model);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception) {
|
|
|
|
|
|
_notifier.Error(T("Listing themes failed: " + exception.Message));
|
|
|
|
|
|
return View(new ThemesIndexViewModel());
|
|
|
|
|
|
}
|
2009-12-10 00:15:58 +00:00
|
|
|
|
}
|
2009-12-11 00:01:32 +00:00
|
|
|
|
|
2010-01-15 09:40:29 +00:00
|
|
|
|
[HttpPost]
|
2009-12-11 00:01:32 +00:00
|
|
|
|
public ActionResult Activate(string themeName) {
|
|
|
|
|
|
try {
|
2010-01-20 20:18:42 +00:00
|
|
|
|
if (!_authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme")))
|
2009-12-11 20:02:51 +00:00
|
|
|
|
return new HttpUnauthorizedResult();
|
2009-12-15 19:50:37 +00:00
|
|
|
|
_themeService.SetSiteTheme(themeName);
|
2009-12-11 00:01:32 +00:00
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception) {
|
|
|
|
|
|
_notifier.Error(T("Activating theme failed: " + exception.Message));
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-12-11 00:40:44 +00:00
|
|
|
|
|
|
|
|
|
|
public ActionResult Install() {
|
|
|
|
|
|
return View(new AdminViewModel());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-01-15 09:40:29 +00:00
|
|
|
|
[HttpPost]
|
2009-12-11 00:40:44 +00:00
|
|
|
|
public ActionResult Install(FormCollection input) {
|
|
|
|
|
|
try {
|
2010-01-20 20:18:42 +00:00
|
|
|
|
if (!_authorizer.Authorize(Permissions.ManageThemes, T("Couldn't install theme")))
|
2009-12-11 20:02:51 +00:00
|
|
|
|
return new HttpUnauthorizedResult();
|
2009-12-11 19:49:53 +00:00
|
|
|
|
foreach (string fileName in Request.Files) {
|
|
|
|
|
|
HttpPostedFileBase file = Request.Files[fileName];
|
|
|
|
|
|
_themeService.InstallTheme(file);
|
|
|
|
|
|
}
|
2009-12-11 00:40:44 +00:00
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception) {
|
2009-12-11 23:10:54 +00:00
|
|
|
|
_notifier.Error(T("Installing theme failed: " + exception.Message));
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-01-15 09:40:29 +00:00
|
|
|
|
[HttpPost]
|
2009-12-11 23:10:54 +00:00
|
|
|
|
public ActionResult Uninstall(string themeName) {
|
|
|
|
|
|
try {
|
2010-01-20 20:18:42 +00:00
|
|
|
|
if (!_authorizer.Authorize(Permissions.ManageThemes, T("Couldn't uninstall theme")))
|
2009-12-11 23:10:54 +00:00
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
_themeService.UninstallTheme(themeName);
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception) {
|
|
|
|
|
|
_notifier.Error(T("Uninstalling theme failed: " + exception.Message));
|
2009-12-11 00:40:44 +00:00
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-12-10 00:15:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|