annotate Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 90:d1688622fa88

Autenticando con twitter (falta emprolijar el código, pero autentica!)
author Nelo@Kenia.neluz.int
date Fri, 03 Jun 2011 21:35:59 -0300
parents 475be11edf56
children 7027cda13de3
rev   line source
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
1 using System;
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
2 using System.Web.Mvc;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
3 using System.Web.Routing;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
4 using System.Web.Security;
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
5 using AltNetHispano.Agendas.Twitter;
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
6 using AltNetHispano.Agendas.Web.Models;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
7
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
8 namespace AltNetHispano.Agendas.Web.Controllers
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
9 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
10 public class AccountController : Controller
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
11 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
12
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
13 public IFormsAuthenticationService FormsService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
14 public IMembershipService MembershipService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
15
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
16 protected override void Initialize(RequestContext requestContext)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
17 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
18 if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
19 if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
20
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
21 base.Initialize(requestContext);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
22 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
23
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
24 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
25 // URL: /Account/LogOn
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
26 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
27
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
28 public ActionResult LogOn()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
29 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
30 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
31 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
32
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
33 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
34 public ActionResult LogOn(LogOnModel model, string returnUrl)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
35 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
36 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
37 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
38 if (MembershipService.ValidateUser(model.UserName, model.Password))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
39 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
40 FormsService.SignIn(model.UserName, model.RememberMe);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
41 if (Url.IsLocalUrl(returnUrl))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
42 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
43 return Redirect(returnUrl);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
44 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
45 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
46 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
47 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
48 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
49 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
50 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
51 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
52 ModelState.AddModelError("", "The user name or password provided is incorrect.");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
53 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
54 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
55
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
56 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
57 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
58 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
59
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
60 public ActionResult TwitterLogOn()
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
61 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
62 var oAuth = new oAuthTwitter();
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
63
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
64 if (Request["oauth_token"] == null)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
65 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
66 //Redirect the user to Twitter for authorization.
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
67 //Using oauth_callback for local testing.
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
68 oAuth.CallBackUrl = "http://localhost:1424/Account/TwitterLogOn";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
69 Response.Redirect(oAuth.AuthorizationLinkGet());
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
70 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
71 else
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
72 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
73 //Get the access token and secret.
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
74 oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
75 if (oAuth.TokenSecret.Length > 0)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
76 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
77 //We now have the credentials, so make a call to the Twitter API.
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
78 const string url = "http://twitter.com/account/verify_credentials.xml";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
79 string xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
80
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
81 var username = GetXmlContent(xml, "screen_name");
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
82 //TODO: Validar que este usuario de twitter corresponde a un usuario del sitio
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
83
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
84 FormsService.SignIn(username, false);
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
85 return RedirectToAction("Index", "Home");
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
86
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
87 //POST Test
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
88 //url = "http://twitter.com/statuses/update.xml";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
89 //xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode("Hello @swhitley - Testing the .NET oAuth API"));
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
90 //apiResponse.InnerHtml = Server.HtmlEncode(xml);
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
91 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
92 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
93
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
94 return RedirectToAction("LogOn");
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
95 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
96
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
97 private string GetXmlContent(string xml, string tagName)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
98 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
99 var tagStart = "<" + tagName + ">";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
100 var tagEnd = "</" + tagName + ">";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
101
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
102 var start = xml.IndexOf(tagStart)+tagStart.Length;
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
103 if (start>tagStart.Length)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
104 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
105 var end = xml.IndexOf(tagEnd, start);
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
106 if (end>0)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
107 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
108 return xml.Substring(start, end - start);
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
109 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
110 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
111 return string.Empty;
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
112 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
113
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
114 // **************************************
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
115 // URL: /Account/LogOff
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
116 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
117
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
118 public ActionResult LogOff()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
119 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
120 FormsService.SignOut();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
121
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
122 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
123 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
124
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
125 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
126 // URL: /Account/Register
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 public ActionResult Register()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
130 {
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();
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 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
136 public ActionResult Register(RegisterModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
137 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
138 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
139 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
140 // Attempt to register the user
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
141 MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
142
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
143 if (createStatus == MembershipCreateStatus.Success)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
144 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
145 FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
146 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
147 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
148 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
149 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
150 ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
151 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
152 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
153
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
154 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
155 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
156 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
157 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
158
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
159 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
160 // URL: /Account/ChangePassword
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
161 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
162
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
163 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
164 public ActionResult ChangePassword()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
165 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
166 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
167 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
168 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
169
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
170 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
171 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
172 public ActionResult ChangePassword(ChangePasswordModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
173 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
174 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
175 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
176 if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
177 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
178 return RedirectToAction("ChangePasswordSuccess");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
179 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
180 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
181 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
182 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
183 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
184 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
185
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
186 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
187 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
188 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
189 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
190
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
191 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
192 // URL: /Account/ChangePasswordSuccess
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
193 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
194
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
195 public ActionResult ChangePasswordSuccess()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
196 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
197 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
198 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
199
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
200 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
201 }