Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 179:1deccd6c3cb2
Aplicando seguridad x roles en sitio web
author | nelopauselli |
---|---|
date | Mon, 08 Aug 2011 15:24:26 -0300 |
parents | 3c70b0d8bd69 |
children | beeb06da4398 |
line wrap: on
line source
using System.Web.Mvc; using System.Web.Routing; using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Factories; using AltNetHispano.Agendas.Twitter; using AltNetHispano.Agendas.Web.Services; namespace AltNetHispano.Agendas.Web.Controllers { public class AccountController : Controller { private IFormsAuthenticationService _formsService; protected override void Initialize(RequestContext requestContext) { if (_formsService == null) { _formsService = new FormsAuthenticationService(); } base.Initialize(requestContext); } public ActionResult LogOn() { return View(); } public ActionResult TwitterLogOn() { var oAuth = new OAuthTwitter(); if (Request["oauth_token"] == null) { var action = Url.Action("TwitterLogOn"); var url = Request.Url.Scheme + "://" + Request.Url.Host + (Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty) + action; return Redirect(oAuth.AuthorizationLinkGet(url).ToString()); } var response = oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]); if (response.Length > 0) { var username = OAuthTwitter.GetResponseContent(response, "screen_name"); var nombre = OAuthTwitter.GetResponseContent(response, "name"); //TOD: Esto es temporal. nombre = nombre.Replace('\u00e1', 'á'); nombre = nombre.Replace('\u00e9', 'é'); nombre = nombre.Replace('\u00ed', 'í'); nombre = nombre.Replace('\u00fa', 'ú'); nombre = nombre.Replace('\u00c1', 'Á'); nombre = nombre.Replace('\u00c9', 'É'); nombre = nombre.Replace('\u00cd', 'Í'); nombre = nombre.Replace('\u00d3', 'Ó'); nombre = nombre.Replace('\u00da', 'Ú'); nombre = nombre.Replace('\u00f1', 'ñ'); nombre = nombre.Replace('\u00d1', 'Ñ'); var personaService = AgendaFactory.GetPersonaService(); personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, username, nombre); _formsService.SignIn(Identification.Map[(int)IdentityProviderEnum.Twitter]+username, false); return RedirectToAction("Index", "Home"); } ModelState.AddModelError("", "The user name or password provided is incorrect."); return RedirectToAction("LogOn"); } public ActionResult LogOff() { _formsService.SignOut(); return RedirectToAction("Index", "Home"); } } }