comparison Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs @ 112:0bca45e1e664

Pantalla de Perfil donde se puede asociar la cuenta de twitter al usuario existente
author Nelo@Kenia.neluz.int
date Sat, 11 Jun 2011 01:20:59 -0300
parents
children 0eac9a1c1a6c
comparison
equal deleted inserted replaced
111:90ce239cfa6d 112:0bca45e1e664
1 using System;
2 using System.Linq;
3 using System.Web.Mvc;
4 using AltNetHispano.Agendas.Domain;
5 using AltNetHispano.Agendas.Factories;
6 using AltNetHispano.Agendas.Twitter;
7 using AltNetHispano.Agendas.Web.Models;
8
9 namespace AltNetHispano.Agendas.Web.Controllers
10 {
11 public class PerfilController : Controller
12 {
13 //
14 // GET: /Perfil/
15
16 public ActionResult Index()
17 {
18 var persona = IdentityContext.GetUsuario();
19
20 if (persona == null)
21 {
22 ModelState.AddModelError(string.Empty, "No fue posible recuperar su perfil, vuelva a autenticarse y reintente");
23 return View();
24 }
25
26 var model = new PerfilIndexModel
27 {
28 DisplayName = persona.Nombre,
29 Cuentas = from c in persona.Cuentas
30 select
31 new CuentaDto
32 {IdentityProvider = c.IdentityProvider.ToString(), UserName = c.LogonName}
33 };
34
35 return View(model);
36 }
37
38 public ActionResult AddTwitterAccount()
39 {
40 var oAuth = new OAuthTwitter();
41
42 if (Request["oauth_token"] == null)
43 {
44 var action = Url.Action("AddTwitterAccount");
45 var url = Request.Url.Scheme + "://" + Request.Url.Host +
46 (Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty) + action;
47
48 Response.Redirect(oAuth.AuthorizationLinkGet(url).ToString());
49 }
50 else
51 {
52 var response = oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
53 if (response.Length > 0)
54 {
55 var username =OAuthTwitter.GetResponseContent(response, "screen_name");
56
57 var personaService = AgendaFactory.GetPersonaService();
58
59 personaService.AddCuenta(IdentityProviderEnum.Twitter, username);
60 return RedirectToAction("Index");
61 }
62 }
63 return RedirectToAction("Index");
64 }
65
66 public ActionResult Remove(string identityProvider, string username)
67 {
68 var personaService = AgendaFactory.GetPersonaService();
69
70 IdentityProviderEnum ip;
71 if (!Enum.TryParse<IdentityProviderEnum>(identityProvider, out ip))
72 {
73 ModelState.AddModelError("IdentityProvider", "No se reconoce el identity provider" + identityProvider);
74 return View("Index");
75 }
76
77 personaService.RemoveCuenta(ip, username);
78
79 return RedirectToAction("Index");
80 }
81 }
82 }