comparison 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
comparison
equal deleted inserted replaced
178:33e57fd1a6c9 179:1deccd6c3cb2
8 8
9 namespace AltNetHispano.Agendas.Web.Controllers 9 namespace AltNetHispano.Agendas.Web.Controllers
10 { 10 {
11 public class PerfilController : Controller 11 public class PerfilController : Controller
12 { 12 {
13 public ActionResult Index() 13 [CustomAuthorize(Roles = Roles.Usuario)]
14 public ActionResult Index()
14 { 15 {
15 var persona = IdentityContext.GetUsuario(); 16 var persona = IdentityContext.GetUsuario();
16 17
17 if (persona == null) 18 if (persona == null)
18 { 19 {
33 }; 34 };
34 35
35 return View(model); 36 return View(model);
36 } 37 }
37 38
38 public ActionResult AddGoogleAccount() 39 [CustomAuthorize(Roles = Roles.Usuario)]
40 public ActionResult AddGoogleAccount()
39 { 41 {
40 throw new NotImplementedException(); 42 throw new NotImplementedException();
41 } 43 }
42 44
43 public ActionResult AddTwitterAccount() 45 [CustomAuthorize(Roles = Roles.Usuario)]
46 public ActionResult AddTwitterAccount()
44 { 47 {
45 var oAuth = new OAuthTwitter(); 48 var oAuth = new OAuthTwitter();
46 49
47 if (Request["oauth_token"] == null) 50 if (Request["oauth_token"] == null)
48 { 51 {
64 return RedirectToAction("Index"); 67 return RedirectToAction("Index");
65 } 68 }
66 return RedirectToAction("Index"); 69 return RedirectToAction("Index");
67 } 70 }
68 71
72 [CustomAuthorize(Roles = Roles.Usuario)]
69 public ActionResult Remove(string identityProvider, string username) 73 public ActionResult Remove(string identityProvider, string username)
70 { 74 {
71 var personaService = AgendaFactory.GetPersonaService(); 75 var personaService = AgendaFactory.GetPersonaService();
72 76
73 IdentityProviderEnum ip; 77 IdentityProviderEnum ip;
79 83
80 personaService.RemoveCuenta(ip, username); 84 personaService.RemoveCuenta(ip, username);
81 85
82 return RedirectToAction("Index"); 86 return RedirectToAction("Index");
83 } 87 }
84 } 88
89 [CustomAuthorize(Roles = Roles.Usuario)]
90 public ActionResult Modificar()
91 {
92 var persona = IdentityContext.GetUsuario();
93 if (persona == null)
94 {
95 this.AddError("No se encontrĂ³ la persona que intenta modificar");
96 return RedirectToAction("Index");
97 }
98
99 var model = new PerfilEditModel
100 {
101 Nombre = persona.Nombre,
102 Twitter = persona.Twitter,
103 EMail = persona.Mail,
104 Blog = persona.Blog
105 };
106
107 return View("Defaulteditor", model);
108 }
109
110 [HttpPost]
111 [CustomAuthorize(Roles = Roles.Usuario)]
112 public ActionResult Modificar(PerfilEditModel model)
113 {
114 if (ModelState.IsValid)
115 {
116 var persona = IdentityContext.GetUsuario();
117
118 var personas = AgendaFactory.GetPersonaService();
119 var r = personas.Update(persona.Id, model.Nombre, model.Twitter, model.EMail, model.Blog);
120 if (r.Succeful)
121 {
122 this.AddNotification("Los datos fueron guardados");
123 return RedirectToAction("Index");
124 }
125 this.AddError(r.Message);
126 }
127
128 return View("Defaulteditor", model);
129 }
130 }
85 } 131 }