mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
closes #146 Add New User interface should have roles (currently redirects to Edit User after user is created)
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042414
This commit is contained in:
@@ -11,15 +11,12 @@ using Orchard.Models.Records;
|
|||||||
|
|
||||||
namespace Orchard.DevTools.Controllers {
|
namespace Orchard.DevTools.Controllers {
|
||||||
public class ContentController : Controller {
|
public class ContentController : Controller {
|
||||||
private readonly IRepository<ContentItemRecord> _contentItemRepository;
|
|
||||||
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
|
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
public ContentController(
|
public ContentController(
|
||||||
IRepository<ContentItemRecord> contentItemRepository,
|
|
||||||
IRepository<ContentTypeRecord> contentTypeRepository,
|
IRepository<ContentTypeRecord> contentTypeRepository,
|
||||||
IContentManager contentManager) {
|
IContentManager contentManager) {
|
||||||
_contentItemRepository = contentItemRepository;
|
|
||||||
_contentTypeRepository = contentTypeRepository;
|
_contentTypeRepository = contentTypeRepository;
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
<li>
|
<li>
|
||||||
|
|
||||||
<%= Html.Hidden("Roles[" + index + "].RoleId", entry.RoleId)%>
|
<%= Html.Hidden("Roles[" + index + "].RoleId", entry.RoleId)%>
|
||||||
|
<%= Html.Hidden("Roles[" + index + "].Name", entry.Name)%>
|
||||||
|
|
||||||
<label for="<%="Roles[" + index + "]_Granted"%>"><%= Html.CheckBox("Roles[" + index + "].Granted", entry.Granted)%> <%=Html.Encode(entry.Name)%></label>
|
<label for="<%="Roles[" + index + "]_Granted"%>"><%= Html.CheckBox("Roles[" + index + "].Granted", entry.Granted)%> <%=Html.Encode(entry.Name)%></label>
|
||||||
</li>
|
</li>
|
||||||
|
@@ -37,26 +37,31 @@ namespace Orchard.Users.Controllers {
|
|||||||
public ActionResult Index() {
|
public ActionResult Index() {
|
||||||
var model = new UsersIndexViewModel();
|
var model = new UsersIndexViewModel();
|
||||||
|
|
||||||
var users = _contentManager.Query<User,UserRecord>("user")
|
var users = _contentManager.Query<User, UserRecord>("user")
|
||||||
.Where(x => x.UserName != null)
|
.Where(x => x.UserName != null)
|
||||||
.List();
|
.List();
|
||||||
|
|
||||||
model.Rows = users.Select(x => new UsersIndexViewModel.Row {User = x}).ToList();
|
model.Rows = users.Select(x => new UsersIndexViewModel.Row { User = x }).ToList();
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Create() {
|
public ActionResult Create() {
|
||||||
var model = new UserCreateViewModel();
|
var user = _contentManager.New("user");
|
||||||
|
var model = new UserCreateViewModel {
|
||||||
|
Editors = _contentManager.GetEditors(user)
|
||||||
|
};
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Create(UserCreateViewModel model) {
|
public ActionResult Create(UserCreateViewModel model) {
|
||||||
|
|
||||||
if (model.Password != model.ConfirmPassword) {
|
if (model.Password != model.ConfirmPassword) {
|
||||||
ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").ToString());
|
ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").ToString());
|
||||||
}
|
}
|
||||||
if (ModelState.IsValid == false) {
|
if (ModelState.IsValid == false) {
|
||||||
|
model.Editors = _contentManager.UpdateEditors(_contentManager.New("user"), this);
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
var user = _membershipService.CreateUser(new CreateUserParams(
|
var user = _membershipService.CreateUser(new CreateUserParams(
|
||||||
@@ -64,6 +69,12 @@ namespace Orchard.Users.Controllers {
|
|||||||
model.Password,
|
model.Password,
|
||||||
model.Email,
|
model.Email,
|
||||||
null, null, true));
|
null, null, true));
|
||||||
|
model.Editors = _contentManager.UpdateEditors(user, this);
|
||||||
|
if (ModelState.IsValid == false) {
|
||||||
|
//TODO: rollback transaction
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
return RedirectToAction("edit", new { user.Id });
|
return RedirectToAction("edit", new { user.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
using Orchard.UI.Models;
|
||||||
|
|
||||||
namespace Orchard.Users.ViewModels {
|
namespace Orchard.Users.ViewModels {
|
||||||
public class UserCreateViewModel : AdminViewModel {
|
public class UserCreateViewModel : AdminViewModel {
|
||||||
@@ -14,5 +16,8 @@ namespace Orchard.Users.ViewModels {
|
|||||||
|
|
||||||
[Required, DataType(DataType.Password)]
|
[Required, DataType(DataType.Password)]
|
||||||
public string ConfirmPassword { get; set; }
|
public string ConfirmPassword { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -7,3 +7,7 @@
|
|||||||
<%=Html.EditorFor(m=>m.Password, "inputPasswordLarge") %>
|
<%=Html.EditorFor(m=>m.Password, "inputPasswordLarge") %>
|
||||||
<%=Html.EditorFor(m=>m.ConfirmPassword, "inputPasswordLarge") %>
|
<%=Html.EditorFor(m=>m.ConfirmPassword, "inputPasswordLarge") %>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
<% foreach(var e in Model.Editors) {%>
|
||||||
|
<%=Html.EditorFor(m => e.Model, e.TemplateName, e.Prefix)%>
|
||||||
|
<%} %>
|
||||||
|
Reference in New Issue
Block a user