2009-11-12 03:46:14 +00:00
|
|
|
using System;
|
2009-11-10 17:33:39 +00:00
|
|
|
using System.Linq;
|
2009-11-10 03:41:01 +00:00
|
|
|
using System.Web.Mvc;
|
2009-11-10 17:33:39 +00:00
|
|
|
using Orchard.Data;
|
2009-11-14 02:35:43 +00:00
|
|
|
using Orchard.Localization;
|
2009-11-10 17:33:39 +00:00
|
|
|
using Orchard.Models;
|
2009-11-13 00:19:43 +00:00
|
|
|
using Orchard.Models.Driver;
|
2009-11-12 03:46:14 +00:00
|
|
|
using Orchard.Security;
|
2009-11-12 19:19:45 +00:00
|
|
|
using Orchard.UI.Notify;
|
2009-11-10 17:33:39 +00:00
|
|
|
using Orchard.Users.Models;
|
|
|
|
using Orchard.Users.ViewModels;
|
2009-11-10 03:41:01 +00:00
|
|
|
|
|
|
|
namespace Orchard.Users.Controllers {
|
2009-11-14 02:35:43 +00:00
|
|
|
|
2009-11-13 00:19:43 +00:00
|
|
|
public class AdminController : Controller, IModelUpdater {
|
2009-11-17 05:52:23 +00:00
|
|
|
private readonly IMembershipService _membershipService;
|
2009-11-19 05:17:02 +00:00
|
|
|
private readonly IContentManager _contentManager;
|
2009-11-10 17:33:39 +00:00
|
|
|
private readonly IRepository<UserRecord> _userRepository;
|
|
|
|
private readonly INotifier _notifier;
|
|
|
|
|
|
|
|
public AdminController(
|
2009-11-17 05:52:23 +00:00
|
|
|
IMembershipService membershipService,
|
2009-11-19 05:17:02 +00:00
|
|
|
IContentManager contentManager,
|
2009-11-10 17:33:39 +00:00
|
|
|
IRepository<UserRecord> userRepository,
|
|
|
|
INotifier notifier) {
|
2009-11-17 05:52:23 +00:00
|
|
|
_membershipService = membershipService;
|
2009-11-19 05:17:02 +00:00
|
|
|
_contentManager = contentManager;
|
2009-11-10 17:33:39 +00:00
|
|
|
_userRepository = userRepository;
|
|
|
|
_notifier = notifier;
|
2009-11-14 05:35:58 +00:00
|
|
|
T = NullLocalizer.Instance;
|
2009-11-10 17:33:39 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 19:56:13 +00:00
|
|
|
public IUser CurrentUser { get; set; }
|
2009-11-14 02:35:43 +00:00
|
|
|
|
2009-11-14 05:35:58 +00:00
|
|
|
public Localizer T { get; set; }
|
2009-11-12 19:56:13 +00:00
|
|
|
|
2009-11-10 03:41:01 +00:00
|
|
|
public ActionResult Index() {
|
2009-11-10 17:33:39 +00:00
|
|
|
var model = new UsersIndexViewModel();
|
|
|
|
model.Rows = _userRepository.Fetch(x => x.UserName != null)
|
|
|
|
.Select(x => new UsersIndexViewModel.Row {
|
2009-11-19 05:17:02 +00:00
|
|
|
User = _contentManager.Get(x.Id).As<UserModel>()
|
2009-11-10 17:33:39 +00:00
|
|
|
})
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Create() {
|
|
|
|
var model = new UserCreateViewModel();
|
|
|
|
return View(model);
|
2009-11-10 03:41:01 +00:00
|
|
|
}
|
|
|
|
|
2009-11-10 17:33:39 +00:00
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Create(UserCreateViewModel model) {
|
2009-11-17 05:52:23 +00:00
|
|
|
if (model.Password != model.ConfirmPassword) {
|
|
|
|
ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").ToString());
|
|
|
|
}
|
2009-11-10 17:33:39 +00:00
|
|
|
if (ModelState.IsValid == false) {
|
|
|
|
return View(model);
|
|
|
|
}
|
2009-11-17 05:52:23 +00:00
|
|
|
var user = _membershipService.CreateUser(new CreateUserParams(
|
|
|
|
model.UserName,
|
|
|
|
model.Password,
|
|
|
|
model.Email,
|
|
|
|
null, null, true));
|
2009-11-10 17:33:39 +00:00
|
|
|
return RedirectToAction("edit", new { user.Id });
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Edit(int id) {
|
2009-11-19 05:17:02 +00:00
|
|
|
var model = new UserEditViewModel { User = _contentManager.Get<UserModel>(id) };
|
|
|
|
model.Editors = _contentManager.GetEditors(model.User.ContentItem);
|
2009-11-10 17:33:39 +00:00
|
|
|
return View(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Edit(int id, FormCollection input) {
|
2009-11-19 05:17:02 +00:00
|
|
|
var model = new UserEditViewModel { User = _contentManager.Get<UserModel>(id) };
|
|
|
|
model.Editors = _contentManager.UpdateEditors(model.User.ContentItem, this);
|
2009-11-13 00:19:43 +00:00
|
|
|
|
2009-11-10 17:33:39 +00:00
|
|
|
if (!TryUpdateModel(model, input.ToValueProvider())) {
|
|
|
|
return View(model);
|
|
|
|
}
|
2009-11-14 02:35:43 +00:00
|
|
|
|
|
|
|
_notifier.Information(T("User information updated"));
|
2009-11-10 17:33:39 +00:00
|
|
|
return RedirectToAction("Edit", new { id });
|
|
|
|
}
|
2009-11-12 03:46:14 +00:00
|
|
|
|
2009-11-13 00:19:43 +00:00
|
|
|
|
|
|
|
bool IModelUpdater.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
|
|
|
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
|
|
|
}
|
2009-11-10 03:41:01 +00:00
|
|
|
}
|
2009-11-10 17:33:39 +00:00
|
|
|
|
2009-11-10 03:41:01 +00:00
|
|
|
}
|