# HG changeset patch # User nelo@MTEySS.neluz.int # Date 1300073743 10800 # Node ID 74eb4577d4475759a35c950bab230e0f862518ac # Parent 8ed4a806ebe0d9302cacfb9ed6308b2ed275714c HttpContext identity provider Requerimiento de autenticación para registrar un nuevo evento o modificar uno existente diff -r 8ed4a806ebe0 -r 74eb4577d447 Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs --- 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 diff -r 8ed4a806ebe0 -r 74eb4577d447 Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj --- 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 @@ Global.asax + diff -r 8ed4a806ebe0 -r 74eb4577d447 Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.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) diff -r 8ed4a806ebe0 -r 74eb4577d447 Agendas/trunk/src/Agendas.Web/Global.asax.cs --- 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 diff -r 8ed4a806ebe0 -r 74eb4577d447 Agendas/trunk/src/Agendas.Web/HttpContextIdentityProvider.asax.cs --- /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