annotate 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
rev   line source
115
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
1 using System.Web.Mvc;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
2 using System.Web.Routing;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
3 using System.Web.Security;
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
4 using AltNetHispano.Agendas.Domain;
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
5 using AltNetHispano.Agendas.Factories;
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
6 using AltNetHispano.Agendas.Twitter;
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
7 using AltNetHispano.Agendas.Web.Models;
93
65f0b3d70c18 Reordenando clases e interfaces
Nelo@Kenia.neluz.int
parents: 92
diff changeset
8 using AltNetHispano.Agendas.Web.Services;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
9
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 10
diff changeset
10 namespace AltNetHispano.Agendas.Web.Controllers
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
11 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
12 public class AccountController : Controller
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
13 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
14
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
15 public IFormsAuthenticationService FormsService { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
16
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
17 protected override void Initialize(RequestContext requestContext)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
18 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
19 if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
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 public ActionResult LogOn()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
25 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
26 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
27 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
28
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
29 public ActionResult TwitterLogOn()
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
30 {
94
db4b1e2cae49 Cambio del nombre de la clase Ponente a Persona
Nelo@Kenia.neluz.int
parents: 93
diff changeset
31 var oAuth = new OAuthTwitter();
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
32
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
33 if (Request["oauth_token"] == null)
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
34 {
92
7027cda13de3 Armado de la url de retorno en base a la url del request
Nelo@Kenia.neluz.int
parents: 90
diff changeset
35 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
36 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
37 (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
38
115
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
39 return 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
40 }
115
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
41
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
42 var response = oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
43 if (response.Length > 0)
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
44 {
115
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
45 var username = OAuthTwitter.GetResponseContent(response, "screen_name");
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
46 var nombre = OAuthTwitter.GetResponseContent(response, "name");
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
47
115
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
48 var personaService = AgendaFactory.GetPersonaService();
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
49 personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, username, nombre);
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
50
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
51 FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.Twitter]+username, false);
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
52 return RedirectToAction("Index", "Home");
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
53 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
54
115
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
55 ModelState.AddModelError("", "The user name or password provided is incorrect.");
7a2eeb9e9bf9 Crear cuenta interna asociada
Nelo@Kenia.neluz.int
parents: 112
diff changeset
56
90
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
57 return RedirectToAction("LogOn");
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
58 }
d1688622fa88 Autenticando con twitter (falta emprolijar el código, pero autentica!)
Nelo@Kenia.neluz.int
parents: 34
diff changeset
59
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
60 public ActionResult LogOff()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
61 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
62 FormsService.SignOut();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
63 return RedirectToAction("Index", "Home");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
64 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
65 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
66 }