Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 142:62dc9fb3a03e
Quitando cuentas BuiltIn
author | Nelo@Guinea.neluz.int |
---|---|
date | Mon, 01 Aug 2011 00:28:04 -0300 |
parents | 7a2eeb9e9bf9 |
children | 3c70b0d8bd69 |
comparison
equal
deleted
inserted
replaced
141:a5ff4de4a1d3 | 142:62dc9fb3a03e |
---|---|
11 { | 11 { |
12 public class AccountController : Controller | 12 public class AccountController : Controller |
13 { | 13 { |
14 | 14 |
15 public IFormsAuthenticationService FormsService { get; set; } | 15 public IFormsAuthenticationService FormsService { get; set; } |
16 public IMembershipService MembershipService { get; set; } | |
17 | 16 |
18 protected override void Initialize(RequestContext requestContext) | 17 protected override void Initialize(RequestContext requestContext) |
19 { | 18 { |
20 if (FormsService == null) { FormsService = new FormsAuthenticationService(); } | 19 if (FormsService == null) { FormsService = new FormsAuthenticationService(); } |
21 if (MembershipService == null) { MembershipService = new AccountMembershipService(); } | |
22 | 20 |
23 base.Initialize(requestContext); | 21 base.Initialize(requestContext); |
24 } | 22 } |
25 | 23 |
26 // ************************************** | |
27 // URL: /Account/LogOn | |
28 // ************************************** | |
29 | |
30 public ActionResult LogOn() | 24 public ActionResult LogOn() |
31 { | 25 { |
32 return View(); | 26 return View(); |
33 } | |
34 | |
35 [HttpPost] | |
36 public ActionResult LogOn(LogOnModel model, string returnUrl) | |
37 { | |
38 if (ModelState.IsValid) | |
39 { | |
40 if (MembershipService.ValidateUser(model.UserName, model.Password)) | |
41 { | |
42 var personaService = AgendaFactory.GetPersonaService(); | |
43 if (personaService.Validate(IdentityProviderEnum.BuiltIn, model.UserName)) | |
44 { | |
45 FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.BuiltIn] + model.UserName, model.RememberMe); | |
46 if (Url.IsLocalUrl(returnUrl)) | |
47 return Redirect(returnUrl); | |
48 return RedirectToAction("Index", "Home"); | |
49 } | |
50 } | |
51 ModelState.AddModelError("", "The user name or password provided is incorrect."); | |
52 } | |
53 | |
54 // If we got this far, something failed, redisplay form | |
55 return View(model); | |
56 } | 27 } |
57 | 28 |
58 public ActionResult TwitterLogOn() | 29 public ActionResult TwitterLogOn() |
59 { | 30 { |
60 var oAuth = new OAuthTwitter(); | 31 var oAuth = new OAuthTwitter(); |
84 ModelState.AddModelError("", "The user name or password provided is incorrect."); | 55 ModelState.AddModelError("", "The user name or password provided is incorrect."); |
85 | 56 |
86 return RedirectToAction("LogOn"); | 57 return RedirectToAction("LogOn"); |
87 } | 58 } |
88 | 59 |
89 // ************************************** | |
90 // URL: /Account/LogOff | |
91 // ************************************** | |
92 | |
93 public ActionResult LogOff() | 60 public ActionResult LogOff() |
94 { | 61 { |
95 FormsService.SignOut(); | 62 FormsService.SignOut(); |
96 | |
97 return RedirectToAction("Index", "Home"); | 63 return RedirectToAction("Index", "Home"); |
98 } | 64 } |
99 | |
100 // ************************************** | |
101 // URL: /Account/Register | |
102 // ************************************** | |
103 | |
104 public ActionResult Register() | |
105 { | |
106 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
107 return View(); | |
108 } | |
109 | |
110 [HttpPost] | |
111 public ActionResult Register(RegisterModel model, string returnUrl) | |
112 { | |
113 if (ModelState.IsValid) | |
114 { | |
115 // Attempt to register the user | |
116 MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); | |
117 | |
118 if (createStatus == MembershipCreateStatus.Success) | |
119 { | |
120 var personaService = AgendaFactory.GetPersonaService(); | |
121 if (personaService.CreateIfNotExist(IdentityProviderEnum.BuiltIn, model.UserName, model.Nombre)) | |
122 { | |
123 FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.BuiltIn] + model.UserName, false); | |
124 if (Url.IsLocalUrl(returnUrl)) | |
125 return Redirect(returnUrl); | |
126 return RedirectToAction("Index", "Home"); | |
127 } | |
128 } | |
129 ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); | |
130 } | |
131 | |
132 // If we got this far, something failed, redisplay form | |
133 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
134 return View(model); | |
135 } | |
136 | |
137 // ************************************** | |
138 // URL: /Account/ChangePassword | |
139 // ************************************** | |
140 | |
141 [Authorize] | |
142 public ActionResult ChangePassword() | |
143 { | |
144 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
145 return View(); | |
146 } | |
147 | |
148 [Authorize] | |
149 [HttpPost] | |
150 public ActionResult ChangePassword(ChangePasswordModel model) | |
151 { | |
152 if (ModelState.IsValid) | |
153 { | |
154 if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) | |
155 { | |
156 return RedirectToAction("ChangePasswordSuccess"); | |
157 } | |
158 else | |
159 { | |
160 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); | |
161 } | |
162 } | |
163 | |
164 // If we got this far, something failed, redisplay form | |
165 ViewBag.PasswordLength = MembershipService.MinPasswordLength; | |
166 return View(model); | |
167 } | |
168 | |
169 // ************************************** | |
170 // URL: /Account/ChangePasswordSuccess | |
171 // ************************************** | |
172 | |
173 public ActionResult ChangePasswordSuccess() | |
174 { | |
175 return View(); | |
176 } | |
177 | |
178 } | 65 } |
179 } | 66 } |