mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Implementing Users AdminController and views
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4039450
This commit is contained in:
@@ -1,10 +1,67 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Notify;
|
||||
using Orchard.Users.Models;
|
||||
using Orchard.Users.ViewModels;
|
||||
|
||||
namespace Orchard.Users.Controllers {
|
||||
public class AdminController : Controller {
|
||||
public ActionResult Index() {
|
||||
return View();
|
||||
private readonly IModelManager _modelManager;
|
||||
private readonly IRepository<UserRecord> _userRepository;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public AdminController(
|
||||
IModelManager modelManager,
|
||||
IRepository<UserRecord> userRepository,
|
||||
INotifier notifier) {
|
||||
_modelManager = modelManager;
|
||||
_userRepository = userRepository;
|
||||
_notifier = notifier;
|
||||
}
|
||||
|
||||
public ActionResult Index() {
|
||||
var model = new UsersIndexViewModel();
|
||||
model.Rows = _userRepository.Fetch(x => x.UserName != null)
|
||||
.Select(x => new UsersIndexViewModel.Row {
|
||||
User = _modelManager.Get(x.Id).As<UserModel>()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
var model = new UserCreateViewModel();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(UserCreateViewModel model) {
|
||||
if (ModelState.IsValid == false) {
|
||||
return View(model);
|
||||
}
|
||||
var user = _modelManager.New("user");
|
||||
user.As<UserModel>().Record = new UserRecord { UserName = model.UserName, Email = model.Email };
|
||||
_modelManager.Create(user);
|
||||
return RedirectToAction("edit", new { user.Id });
|
||||
}
|
||||
|
||||
public ActionResult Edit(int id) {
|
||||
var model = new UserEditViewModel { User = _modelManager.Get(id) };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(int id, FormCollection input) {
|
||||
var model = new UserEditViewModel { User = _modelManager.Get(id) };
|
||||
if (!TryUpdateModel(model, input.ToValueProvider())) {
|
||||
return View(model);
|
||||
}
|
||||
_notifier.Information("User information updated");
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -68,9 +68,18 @@
|
||||
<Compile Include="Models\UserRecord.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\MembershipService.cs" />
|
||||
<Compile Include="ViewModels\UserCreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\UserEditViewModel.cs" />
|
||||
<Compile Include="ViewModels\UsersIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\Admin\Edit.aspx" />
|
||||
<Content Include="Views\Admin\Create.aspx" />
|
||||
<Content Include="Views\Admin\EditorTemplates\UserEditViewModel.ascx" />
|
||||
<Content Include="Views\Admin\EditorTemplates\inputTextLarge.ascx" />
|
||||
<Content Include="Views\Admin\EditorTemplates\UserCreateViewModel.ascx" />
|
||||
<Content Include="Views\Admin\Index.aspx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Users.ViewModels {
|
||||
public class UserCreateViewModel : AdminViewModel {
|
||||
[Required]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.ViewModels {
|
||||
public class UserEditViewModel : AdminViewModel {
|
||||
public IModel User { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
get { return User.Id; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string UserName {
|
||||
get { return User.As<UserModel>().Record.UserName; }
|
||||
set { User.As<UserModel>().Record.UserName = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Email {
|
||||
get { return User.As<UserModel>().Record.Email; }
|
||||
set { User.As<UserModel>().Record.Email = value; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.ViewModels {
|
||||
|
||||
public class UsersIndexViewModel : AdminViewModel {
|
||||
public class Row {
|
||||
public UserModel User { get; set; }
|
||||
}
|
||||
|
||||
public IList<Row> Rows { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Users.ViewModels.UserCreateViewModel>" %>
|
||||
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head runat="server">
|
||||
<title>Add a new User</title>
|
||||
<% Html.Include("Head"); %>
|
||||
</head>
|
||||
<body>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-u">
|
||||
<h2 class="separator">
|
||||
Add a new User</h2>
|
||||
|
||||
</div>
|
||||
<div class="yui-u">
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ol>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<%= Html.EditorForModel() %>
|
||||
<li class="clearLayout">
|
||||
<input class="button" type="submit" value="Create" />
|
||||
<%=Html.ActionLink("Cancel", "Index", new{}, new{@class="button"}) %></li>
|
||||
</ol>
|
||||
<%}/*EndForm*/%>
|
||||
</div>
|
||||
<% Html.Include("Footer"); %>
|
||||
</body>
|
||||
</html>
|
34
src/Orchard.Web/Packages/Orchard.Users/Views/Admin/Edit.aspx
Normal file
34
src/Orchard.Web/Packages/Orchard.Users/Views/Admin/Edit.aspx
Normal file
@@ -0,0 +1,34 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Users.ViewModels.UserEditViewModel>" %>
|
||||
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head runat="server">
|
||||
<title>Edit User</title>
|
||||
<% Html.Include("Head"); %>
|
||||
</head>
|
||||
<body>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-u">
|
||||
<h2 class="separator">
|
||||
Edit User</h2>
|
||||
<p class="bottomSpacer">
|
||||
<%=Html.ActionLink("Users", "Index") %> > Edit #<%=Model.Id%> <strong><%=Html.Encode(Model.UserName)%></strong>
|
||||
</p>
|
||||
</div>
|
||||
<div class="yui-u">
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ol>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<%= Html.EditorForModel() %>
|
||||
<li class="clearLayout">
|
||||
<input class="button" type="submit" value="Save" />
|
||||
<%=Html.ActionLink("Cancel", "Index", new{}, new{@class="button"}) %>
|
||||
</li>
|
||||
</ol>
|
||||
<%}/*EndForm*/%>
|
||||
</div>
|
||||
<% Html.Include("Footer"); %>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Users.ViewModels.UserCreateViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Utility" %>
|
||||
|
||||
<ol>
|
||||
<%=Html.EditorFor(m=>m.UserName, "inputTextLarge") %>
|
||||
<%=Html.EditorFor(m=>m.Email, "inputTextLarge") %>
|
||||
</ol>
|
@@ -0,0 +1,8 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Users.ViewModels.UserEditViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Utility" %>
|
||||
|
||||
<ol>
|
||||
<%=Html.EditorFor(m=>m.Id) %>
|
||||
<%=Html.EditorFor(m=>m.UserName, "inputTextLarge") %>
|
||||
<%=Html.EditorFor(m=>m.Email, "inputTextLarge") %>
|
||||
</ol>
|
@@ -0,0 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
|
||||
<li>
|
||||
<%=Html.LabelForModel() %>
|
||||
<%=Html.TextBox("",Model,new{@class="inputText inputTextLarge"}) %>
|
||||
<%=Html.ValidationMessage("","*")%>
|
||||
</li>
|
@@ -0,0 +1,56 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Users.ViewModels.UsersIndexViewModel>" %>
|
||||
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head runat="server">
|
||||
<title>Manage Users</title>
|
||||
<% Html.Include("Head"); %>
|
||||
</head>
|
||||
<body>
|
||||
<% Html.Include("Header"); %>
|
||||
<% Html.BeginForm(); %>
|
||||
<div class="yui-g">
|
||||
<h2>
|
||||
Manage Users</h2>
|
||||
|
||||
<%=Html.ValidationSummary() %>
|
||||
<%=Html.ActionLink("Add a new user", "Create", new {}, new {@class="floatRight topSpacer"}) %>
|
||||
<table id="pluginListTable" cellspacing="0" class="clearLayout">
|
||||
<colgroup>
|
||||
<col id="Name" />
|
||||
<col id="Email" />
|
||||
<col id="Edit" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
Name
|
||||
</th>
|
||||
<th scope="col">
|
||||
Email
|
||||
</th>
|
||||
<th scope="col">
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<% foreach (var row in Model.Rows) { %>
|
||||
<tr>
|
||||
<td>
|
||||
<%=Html.Encode(row.User.As<IUser>().UserName) %>
|
||||
</td>
|
||||
<td>
|
||||
<%=Html.Encode(row.User.As<IUser>().Email) %>
|
||||
</td>
|
||||
<td>
|
||||
<%=Html.ActionLink("Edit", "Edit", new { row.User.Id })%>
|
||||
</td>
|
||||
</tr>
|
||||
<%}%>
|
||||
</table>
|
||||
</div>
|
||||
<% Html.EndForm(); %>
|
||||
<% Html.Include("Footer"); %>
|
||||
</body>
|
||||
</html>
|
@@ -23,11 +23,6 @@
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
|
||||
<appSettings/>
|
||||
|
||||
<connectionStrings>
|
||||
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
|
||||
<system.web>
|
||||
|
||||
@@ -37,7 +32,7 @@
|
||||
affects performance, set this value to true only
|
||||
during development.
|
||||
-->
|
||||
<compilation debug="false">
|
||||
<compilation debug="true">
|
||||
<assemblies>
|
||||
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
@@ -50,54 +45,7 @@
|
||||
</assemblies>
|
||||
</compilation>
|
||||
|
||||
<!--
|
||||
The <authentication> section enables configuration
|
||||
of the security authentication mode used by
|
||||
ASP.NET to identify an incoming user.
|
||||
-->
|
||||
<authentication mode="Forms">
|
||||
<forms loginUrl="~/Account/LogOn" timeout="2880" />
|
||||
</authentication>
|
||||
|
||||
<membership>
|
||||
<providers>
|
||||
<clear/>
|
||||
<add name="AspNetSqlMembershipProvider"
|
||||
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
|
||||
connectionStringName="ApplicationServices"
|
||||
enablePasswordRetrieval="false"
|
||||
enablePasswordReset="true"
|
||||
requiresQuestionAndAnswer="false"
|
||||
requiresUniqueEmail="false"
|
||||
passwordFormat="Hashed"
|
||||
maxInvalidPasswordAttempts="5"
|
||||
minRequiredPasswordLength="6"
|
||||
minRequiredNonalphanumericCharacters="0"
|
||||
passwordAttemptWindow="10"
|
||||
passwordStrengthRegularExpression=""
|
||||
applicationName="/"
|
||||
/>
|
||||
</providers>
|
||||
</membership>
|
||||
|
||||
<profile>
|
||||
<providers>
|
||||
<clear/>
|
||||
<add name="AspNetSqlProfileProvider"
|
||||
type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
|
||||
connectionStringName="ApplicationServices"
|
||||
applicationName="/"
|
||||
/>
|
||||
</providers>
|
||||
</profile>
|
||||
|
||||
<roleManager enabled="false">
|
||||
<providers>
|
||||
<clear />
|
||||
<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</providers>
|
||||
</roleManager>
|
||||
|
||||
<!--
|
||||
The <customErrors> section enables configuration
|
||||
|
Reference in New Issue
Block a user