diff Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs @ 179:1deccd6c3cb2

Aplicando seguridad x roles en sitio web
author nelopauselli
date Mon, 08 Aug 2011 15:24:26 -0300
parents 97e51ddeeb58
children 222362c29416
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs	Mon Aug 08 12:30:37 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs	Mon Aug 08 15:24:26 2011 -0300
@@ -10,7 +10,8 @@
 {
     public class PerfilController : Controller
     {
-        public ActionResult Index()
+		[CustomAuthorize(Roles = Roles.Usuario)]
+		public ActionResult Index()
         {
         	var persona = IdentityContext.GetUsuario();
 
@@ -35,12 +36,14 @@
         	return View(model);
         }
 
-        public ActionResult AddGoogleAccount()
+		[CustomAuthorize(Roles = Roles.Usuario)]
+		public ActionResult AddGoogleAccount()
         {
             throw new NotImplementedException();
         }
 
-        public ActionResult AddTwitterAccount()
+		[CustomAuthorize(Roles = Roles.Usuario)]
+		public ActionResult AddTwitterAccount()
 		{
 			var oAuth = new OAuthTwitter();
 
@@ -66,6 +69,7 @@
 			return RedirectToAction("Index");
 		}
 
+		[CustomAuthorize(Roles = Roles.Usuario)]
 		public ActionResult Remove(string identityProvider, string username)
 		{
 			var personaService = AgendaFactory.GetPersonaService();
@@ -81,5 +85,47 @@
 
 			return RedirectToAction("Index");
 		}
-    }
+
+		[CustomAuthorize(Roles = Roles.Usuario)]
+		public ActionResult Modificar()
+		{
+			var persona = IdentityContext.GetUsuario();
+			if (persona == null)
+			{
+				this.AddError("No se encontrĂ³ la persona que intenta modificar");
+				return RedirectToAction("Index");
+			}
+
+			var model = new PerfilEditModel
+			{
+				Nombre = persona.Nombre,
+				Twitter = persona.Twitter,
+				EMail = persona.Mail,
+				Blog = persona.Blog
+			};
+
+			return View("Defaulteditor", model);
+		}
+
+		[HttpPost]
+		[CustomAuthorize(Roles = Roles.Usuario)]
+		public ActionResult Modificar(PerfilEditModel model)
+		{
+			if (ModelState.IsValid)
+			{
+				var persona = IdentityContext.GetUsuario();
+
+				var personas = AgendaFactory.GetPersonaService();
+				var r = personas.Update(persona.Id, model.Nombre, model.Twitter, model.EMail, model.Blog);
+				if (r.Succeful)
+				{
+					this.AddNotification("Los datos fueron guardados");
+					return RedirectToAction("Index");
+				}
+				this.AddError(r.Message);
+			}
+
+			return View("Defaulteditor", model);
+		}
+	}
 }