Converting the LogOn view to a shape, and adding a ShapeResult to render shapes as an ActionResult without the need of a dedicated view

Work Item: 17046

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-01-06 15:29:28 -08:00
parent 3d4cb3ca45
commit f86c4b1375
8 changed files with 27 additions and 14 deletions

View File

@@ -371,6 +371,9 @@
<ItemGroup>
<Content Include="Containers\Views\Parts.Container.Contained.SummaryAdmin.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Shapes\Views\ShapeResult\Display.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -0,0 +1 @@
@Display(Model)

View File

@@ -5,11 +5,11 @@ using System.Security.Principal;
using System.Web.Mvc;
using System.Web.Security;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Mvc.Extensions;
using Orchard.Security;
using Orchard.Themes;
using Orchard.Users.Services;
using Orchard.Users.ViewModels;
using Orchard.ContentManagement;
using Orchard.Users.Models;
using Orchard.UI.Notify;
@@ -44,7 +44,8 @@ namespace Orchard.Users.Controllers {
if (currentUser == null) {
Logger.Information("Access denied to anonymous request on {0}", returnUrl);
return View("LogOn", new LogOnViewModel {Title = "Access Denied"});
var shape = _orchardServices.New.LogOn().Title(T("Access Denied").Text);
return new ShapeResult(shape);
}
//TODO: (erikpo) Add a setting for whether or not to log access denieds since these can fill up a database pretty fast from bots on a high traffic site
@@ -57,7 +58,8 @@ namespace Orchard.Users.Controllers {
if (_authenticationService.GetAuthenticatedUser() != null)
return Redirect("~/");
return View(new LogOnViewModel { Title = T("Log On").Text });
var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
return new ShapeResult(shape);
}
[HttpPost]
@@ -66,7 +68,8 @@ namespace Orchard.Users.Controllers {
public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl) {
var user = ValidateLogOn(userNameOrEmail, password);
if (!ModelState.IsValid) {
return View(new LogOnViewModel { Title = T("Log On").Text });
var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
return new ShapeResult(shape);
}
_authenticationService.SignIn(user, false);

View File

@@ -75,7 +75,6 @@
<Compile Include="AdminMenu.cs" />
<Compile Include="Services\MissingSettingsBanner.cs" />
<Compile Include="Services\UserService.cs" />
<Compile Include="ViewModels\LogOnViewModel.cs" />
<Compile Include="ViewModels\UserCreateViewModel.cs" />
<Compile Include="ViewModels\UserEditViewModel.cs" />
<Compile Include="ViewModels\UsersIndexViewModel.cs" />
@@ -90,7 +89,6 @@
<Content Include="Views\Account\ChallengeEmailSuccess.cshtml" />
<Content Include="Views\Account\ChallengeEmailSent.cshtml" />
<Content Include="Views\Account\ChallengeEmailFail.cshtml" />
<Content Include="Views\Account\LogOn.cshtml" />
<Content Include="Views\Account\Register.cshtml" />
<Content Include="Views\Admin\Edit.cshtml" />
<Content Include="Views\Admin\Create.cshtml" />
@@ -129,6 +127,9 @@
<ItemGroup>
<Content Include="Views\Account\LostPassword.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\LogOn.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -1,5 +0,0 @@
namespace Orchard.Users.ViewModels {
public class LogOnViewModel {
public string Title { get; set; }
}
}

View File

@@ -1,12 +1,11 @@
@model Orchard.Users.ViewModels.LogOnViewModel
@using Orchard.ContentManagement;
@using Orchard.ContentManagement;
@{
var userCanRegister = @WorkContext.CurrentSite.As<Orchard.Users.Models.RegistrationSettingsPart>().UsersCanRegister;
var enableLostPassword = @WorkContext.CurrentSite.As<Orchard.Users.Models.RegistrationSettingsPart>().EnableLostPassword;
}
<h1 class="page-title">@Html.TitleForPage(Model.Title)</h1>
<h1 class="page-title">@Html.TitleForPage((string)Model.Title)</h1>
<p>
@T("Please enter your username and password.")
@if(userCanRegister) { @Html.ActionLink(T("Register").Text, "Register") @T(" if you don't have an account.") }

View File

@@ -0,0 +1,10 @@
using System.Web.Mvc;
namespace Orchard.Mvc {
public class ShapeResult : ViewResult {
public ShapeResult(dynamic shape) {
ViewData.Model = shape;
ViewName = "~/Core/Shapes/Views/ShapeResult/Display.cshtml";
}
}
}

View File

@@ -181,6 +181,7 @@
<Compile Include="Messaging\Services\DefaultMessageManager.cs" />
<Compile Include="Mvc\Extensions\ControllerExtensions.cs" />
<Compile Include="Mvc\IOrchardViewPage.cs" />
<Compile Include="Mvc\ShapeResult.cs" />
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
<Compile Include="Mvc\ViewEngines\Razor\IRazorCompilationEvents.cs" />
<Compile Include="Security\IEncryptionService.cs" />