Mercurial > altnet-hispano
changeset 19:74eb4577d447
HttpContext identity provider
Requerimiento de autenticación para registrar un nuevo evento o modificar uno existente
author | nelo@MTEySS.neluz.int |
---|---|
date | Mon, 14 Mar 2011 00:35:43 -0300 |
parents | 8ed4a806ebe0 |
children | c5a99dde072f |
files | Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs Agendas/trunk/src/Agendas.Web/Global.asax.cs Agendas/trunk/src/Agendas.Web/HttpContextIdentityProvider.asax.cs |
diffstat | 5 files changed, 37 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Mon Mar 14 00:26:44 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Mon Mar 14 00:35:43 2011 -0300 @@ -5,11 +5,20 @@ { public static class AgendaFactory { - private static readonly Agenda Agenda = new Agenda(null, null, null, new EventoRepository()); + private static Agenda _agenda; + private static ISeguridad _seguridad; + + public static Agenda GetAgenda() + { + if (_agenda==null) + _agenda = new Agenda(null, null, _seguridad, new EventoRepository()); - public static Agenda GetAgenda() - { - return Agenda; + return _agenda; } + + public static void SetIdentityProvider(ISeguridad seguridad) + { + _seguridad = seguridad; + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Mon Mar 14 00:26:44 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Mon Mar 14 00:35:43 2011 -0300 @@ -63,6 +63,7 @@ <Compile Include="Global.asax.cs"> <DependentUpon>Global.asax</DependentUpon> </Compile> + <Compile Include="HttpContextIdentityProvider.asax.cs" /> <Compile Include="Models\AccountModels.cs" /> <Compile Include="Models\AgendaModel.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
--- a/Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs Mon Mar 14 00:26:44 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs Mon Mar 14 00:35:43 2011 -0300 @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Agendas.Factories; using Agendas.Web.Models; -using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Domain.Exceptions; namespace Agendas.Web.Controllers @@ -28,13 +26,15 @@ }; } - public ActionResult New() + [Authorize] + public ActionResult New() { return View(); } [HttpPost] - public ActionResult New(AgendaNewModel model) + [Authorize] + public ActionResult New(AgendaNewModel model) { if (ModelState.IsValid) { @@ -54,6 +54,7 @@ return View(model); } + [Authorize] public ActionResult Edit(string id) { var agenda = AgendaFactory.GetAgenda(); @@ -68,6 +69,7 @@ } [HttpPost] + [Authorize] public ActionResult Edit(AgendaEditModel model) { if (ModelState.IsValid)
--- a/Agendas/trunk/src/Agendas.Web/Global.asax.cs Mon Mar 14 00:26:44 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Global.asax.cs Mon Mar 14 00:35:43 2011 -0300 @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web; using System.Web.Mvc; using System.Web.Routing; +using Agendas.Factories; namespace Agendas.Web { @@ -35,6 +35,8 @@ RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); + + AgendaFactory.SetIdentityProvider(new HttpContextIdentityProvider()); } } } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/HttpContextIdentityProvider.asax.cs Mon Mar 14 00:35:43 2011 -0300 @@ -0,0 +1,14 @@ +using System.Security.Principal; +using System.Web; +using AltNetHispano.Agendas.Domain; + +namespace Agendas.Web +{ + public class HttpContextIdentityProvider : ISeguridad + { + public IPrincipal GetPrincipal() + { + return HttpContext.Current.User; + } + } +} \ No newline at end of file