annotate Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 109:6bd9be78caa0

Merge
author Nelo@Kenia.neluz.int
date Tue, 07 Jun 2011 23:21:07 -0300
parents 1ee5711256db
children 0bca45e1e664
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 {
96
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
41 if (MembershipService.ValidateUser(model.UserName, model.Password))
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
42 {
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
43 var personaService = AgendaFactory.GetPersonaService();
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
44 if (personaService.Validate(IdentityProviderEnum.BuiltIn, model.UserName))
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
45 {
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
46 FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.BuiltIn] + model.UserName, model.RememberMe);
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
47 if (Url.IsLocalUrl(returnUrl))
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
48 return Redirect(returnUrl);
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
49 return RedirectToAction("Index", "Home");
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
50 }
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
51 }
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
52 ModelState.AddModelError("", "The user name or password provided is incorrect.");
10
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 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
56 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
57 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
58
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
59 public ActionResult TwitterLogOn()
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
60 {
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
61 var oAuth = new OAuthTwitter();
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
62
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
63 if (Request["oauth_token"] == null)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
64 {
92
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
65 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
66 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
67 (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
68
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
69 Response.Redirect(oAuth.AuthorizationLinkGet(url).ToString());
90
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 {
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
73 var response = oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
74 if (response.Length > 0)
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
75 {
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
76 var username = GetResponseContent(response, "screen_name");
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
77 var nombre = GetResponseContent(response, "name");
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
78
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
79 var personaService = AgendaFactory.GetPersonaService();
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
80 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
81 {
96
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
82 FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.Twitter]+username, false);
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
83 return RedirectToAction("Index", "Home");
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
84 }
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
85 ModelState.AddModelError("", "The user name or password provided is incorrect.");
90
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 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
88
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
89 return RedirectToAction("LogOn");
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
90 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
91
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
92 private static string GetResponseContent(string response, string tagName)
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
93 {
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
94 var tagStart = "\"" + tagName + "\":";
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
95 var tagEnd = ",";
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
96
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
97 var start = response.IndexOf(tagStart) + tagStart.Length;
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
98 if (start > tagStart.Length)
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
99 {
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
100 var end = response.IndexOf(tagEnd, start);
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
101 if (end > 0)
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
102 {
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
103 return response.Substring(start + 1, end - start - 2);
90
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 }
107
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
106 return string.Empty;
1ee5711256db Utilizando Twitterizer en adapter a Twitter
Nelo@Kenia.neluz.int
parents: 96
diff changeset
107 }
90
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 // **************************************
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
110 // URL: /Account/LogOff
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
111 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
112
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
113 public ActionResult LogOff()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
114 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
115 FormsService.SignOut();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
116
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
117 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
118 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
119
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
120 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
121 // URL: /Account/Register
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
122 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
123
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
124 public ActionResult Register()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
125 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
126 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
127 return View();
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 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
131 public ActionResult Register(RegisterModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
132 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
133 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
134 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
135 // Attempt to register the user
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
136 MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
137
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
138 if (createStatus == MembershipCreateStatus.Success)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
139 {
96
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
140 var personaService = AgendaFactory.GetPersonaService();
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
141 if (personaService.Validate(IdentityProviderEnum.BuiltIn, model.UserName, model.Nombre))
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
142 {
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
143 FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.BuiltIn] + model.UserName, false);
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
144 return RedirectToAction("Index", "Home");
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
145 }
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
146 }
96
1eb5a0e531bf Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents: 94
diff changeset
147 ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
148 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
149
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
150 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
151 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
152 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
153 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
154
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
155 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
156 // URL: /Account/ChangePassword
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 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
160 public ActionResult ChangePassword()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
161 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
162 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
163 return View();
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 [Authorize]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
167 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
168 public ActionResult ChangePassword(ChangePasswordModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
169 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
170 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
171 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
172 if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
173 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
174 return RedirectToAction("ChangePasswordSuccess");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
175 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
176 else
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
177 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
178 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
179 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
180 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
181
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
182 // If we got this far, something failed, redisplay form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
183 ViewBag.PasswordLength = MembershipService.MinPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
184 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
185 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
186
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
187 // **************************************
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
188 // URL: /Account/ChangePasswordSuccess
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 public ActionResult ChangePasswordSuccess()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
192 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
193 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
194 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
195
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
196 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
197 }