annotate Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 94:db4b1e2cae49

Cambio del nombre de la clase Ponente a Persona Se agrega la clase Cuenta para identificar cada una de las cuentas con que se puede autenticar una persona Alta Automatica de cuentas de twitter creando la persona
author Nelo@Kenia.neluz.int
date Sat, 04 Jun 2011 12:11:17 -0300
parents 65f0b3d70c18
children 1eb5a0e531bf
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;
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
5 using AltNetHispano.Agendas.Domain;
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
6 using AltNetHispano.Agendas.Factories;
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
7 using AltNetHispano.Agendas.Twitter;
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
8 using AltNetHispano.Agendas.Web.Models;
93
65f0b3d70c18 Reordenando clases e interfaces
Nelo@Kenia.neluz.int
parents: 92
diff changeset
9 using AltNetHispano.Agendas.Web.Services;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
10
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
11 namespace AltNetHispano.Agendas.Web.Controllers
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
12 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
13 public class AccountController : Controller
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
14 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
15
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
16 public IFormsAuthenticationService FormsService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
17 public IMembershipService MembershipService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
18
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
19 protected override void Initialize(RequestContext requestContext)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
20 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
21 if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
22 if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
23
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
24 base.Initialize(requestContext);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
25 }
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 // URL: /Account/LogOn
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 public ActionResult LogOn()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
32 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
33 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
34 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
35
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
36 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
37 public ActionResult LogOn(LogOnModel model, string returnUrl)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
38 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
39 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
40 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
41 if (MembershipService.ValidateUser(model.UserName, model.Password))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
42 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
43 FormsService.SignIn(model.UserName, model.RememberMe);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
44 if (Url.IsLocalUrl(returnUrl))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
45 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
46 return Redirect(returnUrl);
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 return RedirectToAction("Index", "Home");
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 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
54 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
55 ModelState.AddModelError("", "The user name or password provided is incorrect.");
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 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
60 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
61 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
62
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
63 public ActionResult TwitterLogOn()
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
64 {
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
65 var oAuth = new OAuthTwitter();
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
66
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
67 if (Request["oauth_token"] == null)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
68 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
69 //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
70 //Using oauth_callback for local testing.
92
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
71 var action = Url.Action("TwitterLogOn");
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
72 var url = Request.Url.Scheme + "://" + Request.Url.Host +
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
73 (Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty) + action;
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
74
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
75 oAuth.CallBackUrl = url;
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
76 Response.Redirect(oAuth.AuthorizationLinkGet());
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
77 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
78 else
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
79 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
80 //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
81 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
82 if (oAuth.TokenSecret.Length > 0)
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 //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
85 const string url = "http://twitter.com/account/verify_credentials.xml";
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
86 string xml = oAuth.OAuthWebRequest(OAuthTwitter.Method.GET, url, String.Empty);
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
87
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
88 var username = GetXmlContent(xml, "screen_name");
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
89 var nombre = GetXmlContent(xml, "name");
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
90
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
91 var personaService = AgendaFactory.GetPersonaService();
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
92 if (personaService.Validate(IdentityProviderEnum.Twitter, username, nombre))
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
93 {
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
94 FormsService.SignIn(username, false);
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
95 return RedirectToAction("Index", "Home");
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
96 }
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
97 ModelState.AddModelError("", "The user name or password provided is incorrect.");
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
98
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
99
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
100 //POST Test
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
101 //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
102 //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
103 //apiResponse.InnerHtml = Server.HtmlEncode(xml);
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 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
106
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
107 return RedirectToAction("LogOn");
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
108 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
109
93
65f0b3d70c18 Reordenando clases e interfaces
Nelo@Kenia.neluz.int
parents: 92
diff changeset
110 private static string GetXmlContent(string xml, string tagName)
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
111 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
112 var tagStart = "<" + tagName + ">";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
113 var tagEnd = "</" + tagName + ">";
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
114
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
115 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
116 if (start>tagStart.Length)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
117 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
118 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
119 if (end>0)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
120 {
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
121 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
122 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
123 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
124 return string.Empty;
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
125 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
126
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
127 // **************************************
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
128 // URL: /Account/LogOff
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
129 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
130
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
131 public ActionResult LogOff()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
132 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
133 FormsService.SignOut();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
134
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
135 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
136 }
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 // URL: /Account/Register
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
140 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
141
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
142 public ActionResult Register()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
143 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
144 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
145 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
146 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
147
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
148 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
149 public ActionResult Register(RegisterModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
150 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
151 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
152 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
153 // Attempt to register the user
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
154 MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
155
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
156 if (createStatus == MembershipCreateStatus.Success)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
157 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
158 FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
159 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
160 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
161 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
162 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
163 ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
164 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
165 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
166
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
167 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
168 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
169 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
170 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
171
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
172 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
173 // URL: /Account/ChangePassword
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
174 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
175
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
176 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
177 public ActionResult ChangePassword()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
178 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
179 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
180 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
181 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
182
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
183 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
184 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
185 public ActionResult ChangePassword(ChangePasswordModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
186 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
187 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
188 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
189 if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
190 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
191 return RedirectToAction("ChangePasswordSuccess");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
192 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
193 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
194 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
195 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
196 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
197 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
198
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
199 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
200 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
201 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
202 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
203
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
204 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
205 // URL: /Account/ChangePasswordSuccess
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
206 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
207
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
208 public ActionResult ChangePasswordSuccess()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
209 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
210 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
211 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
212
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
213 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
214 }