annotate Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 70:c7264bfc4b71

agregado de properties en clase Evento (UrlInvitacion, UrlWiki, NumeroOrden) modificaciones en proyecto Agendas.Blog modificacion de viewmodel EventoModel - agregado de UrlInvitacion (no requerido)
author jorge.rowies
date Fri, 20 May 2011 12:21:07 -0300
parents 475be11edf56
children d1688622fa88
rev   line source
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
1 using System.Web.Mvc;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
2 using System.Web.Routing;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
3 using System.Web.Security;
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
4 using AltNetHispano.Agendas.Web.Models;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
5
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
6 namespace AltNetHispano.Agendas.Web.Controllers
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
7 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
8 public class AccountController : Controller
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
9 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
11 public IFormsAuthenticationService FormsService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
12 public IMembershipService MembershipService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
13
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
14 protected override void Initialize(RequestContext requestContext)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
15 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
16 if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
17 if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
18
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
19 base.Initialize(requestContext);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
20 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
21
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
22 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
23 // URL: /Account/LogOn
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
24 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
25
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
26 public ActionResult LogOn()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
27 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
28 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
29 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
30
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
31 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
32 public ActionResult LogOn(LogOnModel model, string returnUrl)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
33 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
34 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
35 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
36 if (MembershipService.ValidateUser(model.UserName, model.Password))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
37 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
38 FormsService.SignIn(model.UserName, model.RememberMe);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
39 if (Url.IsLocalUrl(returnUrl))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
40 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
41 return Redirect(returnUrl);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
42 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
43 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
44 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
45 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
46 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
47 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
48 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
49 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
50 ModelState.AddModelError("", "The user name or password provided is incorrect.");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
51 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
52 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
53
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
54 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
55 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
56 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
57
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
58 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
59 // URL: /Account/LogOff
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
60 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
61
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
62 public ActionResult LogOff()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
63 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
64 FormsService.SignOut();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
65
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
66 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
67 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
68
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
69 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
70 // URL: /Account/Register
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
71 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
72
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
73 public ActionResult Register()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
74 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
75 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
76 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
77 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
78
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
79 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
80 public ActionResult Register(RegisterModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
81 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
82 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
83 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
84 // Attempt to register the user
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
85 MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
86
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
87 if (createStatus == MembershipCreateStatus.Success)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
88 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
89 FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
90 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
91 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
92 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
93 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
94 ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
95 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
96 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
97
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
98 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
99 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
100 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
101 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
102
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
103 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
104 // URL: /Account/ChangePassword
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
105 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
106
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
107 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
108 public ActionResult ChangePassword()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
109 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
110 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
111 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
112 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
113
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
114 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
115 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
116 public ActionResult ChangePassword(ChangePasswordModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
117 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
118 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
119 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
120 if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
121 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
122 return RedirectToAction("ChangePasswordSuccess");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
123 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
124 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
125 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
126 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
127 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
128 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
129
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
130 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
131 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
132 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
133 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
134
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
135 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
136 // URL: /Account/ChangePasswordSuccess
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
137 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
138
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
139 public ActionResult ChangePasswordSuccess()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
140 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
141 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
142 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
143
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
144 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
145 }