changeset 96:1eb5a0e531bf

Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios Estructura de aspnetdb dentro de base de datos de altnet hispano, se debe ejecutar: C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe para crear dicha estructura, de todas formas el objetivo seria tener una tabla de usuario y password interna, no parecería ser necesaria toda la estructura de aspnetdb
author Nelo@Kenia.neluz.int
date Sat, 04 Jun 2011 19:37:02 -0300
parents 83d76f6e0a3c
children 2434c2323f3d
files Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj Agendas/trunk/src/Agendas.Domain/Identification.cs Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs Agendas/trunk/src/Agendas.Web/IdentityHelper.cs Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs Agendas/trunk/src/Agendas.Web/Views/Account/Register.cshtml Agendas/trunk/src/Agendas.Web/Web.config
diffstat 9 files changed, 73 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj	Sat Jun 04 19:37:02 2011 -0300
@@ -48,6 +48,7 @@
     <Compile Include="Exceptions\IdentityContextNotConfiguredException.cs" />
     <Compile Include="Exceptions\UsuarioNoAutenticadoException.cs" />
     <Compile Include="Identificable.cs" />
+    <Compile Include="Identification.cs" />
     <Compile Include="IdentityContext.cs" />
     <Compile Include="ISeguridad.cs" />
     <Compile Include="Persona.cs" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Domain/Identification.cs	Sat Jun 04 19:37:02 2011 -0300
@@ -0,0 +1,17 @@
+namespace AltNetHispano.Agendas.Domain
+{
+	public class Identification
+	{
+		public const string Map = " !@";
+
+		public Identification(string name)
+		{
+			char c = name[0];
+			IdentityProvider = (IdentityProviderEnum)Map.IndexOf(c);
+			LogonName = name.Substring(1);
+		}
+
+		public string LogonName { get; set; }
+		public IdentityProviderEnum IdentityProvider { get; set; }
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs	Sat Jun 04 19:37:02 2011 -0300
@@ -11,6 +11,12 @@
 			_personaRepository = personaRepository;
 		}
 
+		public bool Validate(IdentityProviderEnum identityProvider, string username)
+		{
+			var cuenta = _personaRepository.GetCuenta(identityProvider, username);
+			return cuenta != null;
+		}
+
 		public bool Validate(IdentityProviderEnum identityProvider, string username, string nombre)
 		{
 			var cuenta = _personaRepository.GetCuenta(identityProvider, username);
--- a/Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs	Sat Jun 04 19:37:02 2011 -0300
@@ -35,5 +35,21 @@
 			Assert.IsTrue(personaService.Validate(IdentityProviderEnum.Twitter, "nelopauselli", "Nelo Pauselli"));
 			Assert.AreEqual(1, persona.Cuentas.Count());
 		}
+
+		[Test]
+		public void IdentificacionBuiltIn()
+		{
+			var builtIn = new Identification(Identification.Map[(int) IdentityProviderEnum.BuiltIn] + "nelo");
+			Assert.AreEqual(IdentityProviderEnum.BuiltIn, builtIn.IdentityProvider);
+			Assert.AreEqual("nelo", builtIn.LogonName);
+		}
+
+		[Test]
+		public void IdentificacionTwitter()
+		{
+			var builtIn = new Identification(Identification.Map[(int)IdentityProviderEnum.Twitter] + "nelo");
+			Assert.AreEqual(IdentityProviderEnum.Twitter, builtIn.IdentityProvider);
+			Assert.AreEqual("nelo", builtIn.LogonName);
+		}
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs	Sat Jun 04 19:37:02 2011 -0300
@@ -38,22 +38,18 @@
         {
             if (ModelState.IsValid)
             {
-                if (MembershipService.ValidateUser(model.UserName, model.Password))
-                {
-                    FormsService.SignIn(model.UserName, model.RememberMe);
-                    if (Url.IsLocalUrl(returnUrl))
-                    {
-                        return Redirect(returnUrl);
-                    }
-                    else
-                    {
-                        return RedirectToAction("Index", "Home");
-                    }
-                }
-                else
-                {
-                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
-                }
+				if (MembershipService.ValidateUser(model.UserName, model.Password))
+				{
+					var personaService = AgendaFactory.GetPersonaService();
+					if (personaService.Validate(IdentityProviderEnum.BuiltIn, model.UserName))
+					{
+						FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.BuiltIn] + model.UserName, model.RememberMe);
+						if (Url.IsLocalUrl(returnUrl))
+							return Redirect(returnUrl);
+						return RedirectToAction("Index", "Home");
+					}
+				}
+            	ModelState.AddModelError("", "The user name or password provided is incorrect.");
             }
 
             // If we got this far, something failed, redisplay form
@@ -91,7 +87,7 @@
 					var personaService = AgendaFactory.GetPersonaService();
 					if (personaService.Validate(IdentityProviderEnum.Twitter, username, nombre))
 					{
-						FormsService.SignIn(username, false);
+						FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.Twitter]+username, false);
 						return RedirectToAction("Index", "Home");
 					}
 					ModelState.AddModelError("", "The user name or password provided is incorrect.");
@@ -155,13 +151,14 @@
 
                 if (createStatus == MembershipCreateStatus.Success)
                 {
-                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
-                    return RedirectToAction("Index", "Home");
+					var personaService = AgendaFactory.GetPersonaService();
+					if (personaService.Validate(IdentityProviderEnum.BuiltIn, model.UserName, model.Nombre))
+					{
+						FormsService.SignIn(Identification.Map[(int)IdentityProviderEnum.BuiltIn] + model.UserName, false);
+						return RedirectToAction("Index", "Home");
+					}
                 }
-                else
-                {
-                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
-                }
+                ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
             }
 
             // If we got this far, something failed, redisplay form
--- a/Agendas/trunk/src/Agendas.Web/IdentityHelper.cs	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/IdentityHelper.cs	Sat Jun 04 19:37:02 2011 -0300
@@ -10,10 +10,10 @@
 		{
 			var personaRepository = Factories.AgendaFactory.GetPersonaRepository();
 			
-			string logonName = HttpContext.Current.User.Identity.Name;
-			
-			var c = personaRepository.GetCuenta(IdentityProviderEnum.Twitter, logonName);
-			return c == null ? logonName : c.Persona != null ? c.Persona.Nombre : c.LogonName;
+			var identification = new Identification(HttpContext.Current.User.Identity.Name);
+
+			var c = personaRepository.GetCuenta(identification.IdentityProvider, identification.LogonName);
+			return c == null ? identification.LogonName : c.Persona != null ? c.Persona.Nombre : c.LogonName;
 		}
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs	Sat Jun 04 19:37:02 2011 -0300
@@ -47,7 +47,10 @@
 
     public class RegisterModel
     {
-        [Required]
+		[Required]
+		public string Nombre { get; set; }
+		
+		[Required]
         [Display(Name = "User name")]
         public string UserName { get; set; }
 
--- a/Agendas/trunk/src/Agendas.Web/Views/Account/Register.cshtml	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Views/Account/Register.cshtml	Sat Jun 04 19:37:02 2011 -0300
@@ -12,45 +12,8 @@
 
 @using (Html.BeginForm()) {
     @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
-    <div>
-        <fieldset>
-            <legend>Account Information</legend>
-
-            <div class="editor-label">
-                @Html.LabelFor(m => m.UserName)
-            </div>
-            <div class="editor-field">
-                @Html.TextBoxFor(m => m.UserName)
-                @Html.ValidationMessageFor(m => m.UserName)
-            </div>
-
-            <div class="editor-label">
-                @Html.LabelFor(m => m.Email)
-            </div>
-            <div class="editor-field">
-                @Html.TextBoxFor(m => m.Email)
-                @Html.ValidationMessageFor(m => m.Email)
-            </div>
-
-            <div class="editor-label">
-                @Html.LabelFor(m => m.Password)
-            </div>
-            <div class="editor-field">
-                @Html.PasswordFor(m => m.Password)
-                @Html.ValidationMessageFor(m => m.Password)
-            </div>
-
-            <div class="editor-label">
-                @Html.LabelFor(m => m.ConfirmPassword)
-            </div>
-            <div class="editor-field">
-                @Html.PasswordFor(m => m.ConfirmPassword)
-                @Html.ValidationMessageFor(m => m.ConfirmPassword)
-            </div>
-
-            <p>
-                <input type="submit" value="Register" />
-            </p>
-        </fieldset>
-    </div>
+    @Html.EditorForModel()
+    <p>
+        <input type="submit" value="Register" />
+    </p>
 }
--- a/Agendas/trunk/src/Agendas.Web/Web.config	Sat Jun 04 18:33:15 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Web.config	Sat Jun 04 19:37:02 2011 -0300
@@ -6,11 +6,8 @@
 
 <configuration>
 	<connectionStrings>
-		<add name="ApplicationServices"
-			 connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
-			 providerName="System.Data.SqlClient" />
+		<add name="ApplicationServices" connectionString="Data Source=.\sqlexpress;Initial Catalog=AltNetHispano;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
 		<add name="AltNetHispano" connectionString="Data Source=.\sqlexpress;Initial Catalog=AltNetHispano;Integrated Security=SSPI"/>
-
 	</connectionStrings>
 
 	<appSettings>