Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 89:24e9488ac152
mapeo de property UrlInvitacion entre viewmodel y entity
author | jorge.rowies |
---|---|
date | Tue, 31 May 2011 16:31:24 -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 | 2 using System.Web.Routing; |
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 | 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 | 7 { |
8 public class AccountController : Controller | |
9 { | |
10 | |
11 public IFormsAuthenticationService FormsService { get; set; } | |
12 public IMembershipService MembershipService { get; set; } | |
13 | |
14 protected override void Initialize(RequestContext requestContext) | |
15 { | |
16 if (FormsService == null) { FormsService = new FormsAuthenticationService(); } | |
17 if (MembershipService == null) { MembershipService = new AccountMembershipService(); } | |
18 | |
19 base.Initialize(requestContext); | |
20 } | |
21 | |
22 // ************************************** | |
23 // URL: /Account/LogOn | |
24 // ************************************** | |
25 | |
26 public ActionResult LogOn() | |
27 { | |
28 return View(); | |
29 } | |
30 | |
31 [HttpPost] | |
32 public ActionResult LogOn(LogOnModel model, string returnUrl) | |
33 { | |
34 if (ModelState.IsValid) | |
35 { | |
36 if (MembershipService.ValidateUser(model.UserName, model.Password)) | |
37 { | |
38 FormsService.SignIn(model.UserName, model.RememberMe); | |
39 if (Url.IsLocalUrl(returnUrl)) | |
40 { | |
41 return Redirect(returnUrl); | |
42 } | |
43 else | |
44 { | |
45 return RedirectToAction("Index", "Home"); | |
46 } | |
47 } | |
48 else | |
49 { | |
50 ModelState.AddModelError("", "The user name or password provided is incorrect."); | |
51 } | |
52 } | |
53 | |
54 // If we got this far, something failed, redisplay form | |
55 return View(model); | |
56 } | |
57 | |
58 // ************************************** | |
59 // URL: /Account/LogOff | |
60 // ************************************** | |
61 | |
62 public ActionResult LogOff() | |
63 { | |
64 FormsService.SignOut(); | |
65 | |
66 return RedirectToAction("Index", "Home"); | |
67 } | |
68 | |
69 // ************************************** | |
70 // URL: /Account/Register | |
71 // ************************************** | |
72 | |
73 public ActionResult Register() | |
74 { | |
75 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
76 return View(); | |
77 } | |
78 | |
79 [HttpPost] | |
80 public ActionResult Register(RegisterModel model) | |
81 { | |
82 if (ModelState.IsValid) | |
83 { | |
84 // Attempt to register the user | |
85 MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); | |
86 | |
87 if (createStatus == MembershipCreateStatus.Success) | |
88 { | |
89 FormsService.SignIn(model.UserName, false /* createPersistentCookie */); | |
90 return RedirectToAction("Index", "Home"); | |
91 } | |
92 else | |
93 { | |
94 ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); | |
95 } | |
96 } | |
97 | |
98 // If we got this far, something failed, redisplay form | |
99 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
100 return View(model); | |
101 } | |
102 | |
103 // ************************************** | |
104 // URL: /Account/ChangePassword | |
105 // ************************************** | |
106 | |
107 [Authorize] | |
108 public ActionResult ChangePassword() | |
109 { | |
110 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
111 return View(); | |
112 } | |
113 | |
114 [Authorize] | |
115 [HttpPost] | |
116 public ActionResult ChangePassword(ChangePasswordModel model) | |
117 { | |
118 if (ModelState.IsValid) | |
119 { | |
120 if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) | |
121 { | |
122 return RedirectToAction("ChangePasswordSuccess"); | |
123 } | |
124 else | |
125 { | |
126 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); | |
127 } | |
128 } | |
129 | |
130 // If we got this far, something failed, redisplay form | |
131 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
132 return View(model); | |
133 } | |
134 | |
135 // ************************************** | |
136 // URL: /Account/ChangePasswordSuccess | |
137 // ************************************** | |
138 | |
139 public ActionResult ChangePasswordSuccess() | |
140 { | |
141 return View(); | |
142 } | |
143 | |
144 } | |
145 } |