diff Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs @ 113:0eac9a1c1a6c

Soporte para asociar cuentas internas a un usuario ya identificado con twitter
author Carlos Peix
date Sat, 11 Jun 2011 12:44:47 -0300
parents 0bca45e1e664
children 1ce71844ffa4
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs	Sat Jun 11 01:20:59 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/PerfilController.cs	Sat Jun 11 12:44:47 2011 -0300
@@ -1,16 +1,29 @@
 using System;
 using System.Linq;
 using System.Web.Mvc;
+using System.Web.Routing;
 using AltNetHispano.Agendas.Domain;
 using AltNetHispano.Agendas.Factories;
 using AltNetHispano.Agendas.Twitter;
 using AltNetHispano.Agendas.Web.Models;
+using AltNetHispano.Agendas.Web.Services;
 
 namespace AltNetHispano.Agendas.Web.Controllers
 {
     public class PerfilController : Controller
     {
-        //
+		public IMembershipService MembershipService { get; set; }
+
+		protected override void Initialize(RequestContext requestContext)
+		{
+			//if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
+			if (MembershipService == null)
+				MembershipService = new AccountMembershipService();
+
+			base.Initialize(requestContext);
+		}
+
+		//
         // GET: /Perfil/
 
         public ActionResult Index()
@@ -63,6 +76,29 @@
 			return RedirectToAction("Index");
 		}
 
+		public ActionResult AddBuiltInAccount()
+		{
+			return View();
+		}
+
+		[HttpPost]
+		public ActionResult AddBuiltInAccount(LogOnModel model)
+		{
+			if (ModelState.IsValid)
+			{
+				if (MembershipService.ValidateUser(model.UserName, model.Password))
+				{
+					var personaService = AgendaFactory.GetPersonaService();
+					personaService.AddCuenta(IdentityProviderEnum.BuiltIn, model.UserName);
+					RedirectToAction("Index");
+				}
+				ModelState.AddModelError("", "The user name or password provided is incorrect.");
+			}
+
+			// If we got this far, something failed, redisplay form
+			return View(model);
+		}
+
 		public ActionResult Remove(string identityProvider, string username)
 		{
 			var personaService = AgendaFactory.GetPersonaService();