# HG changeset patch
# User Nelo@Kenia.neluz.int
# Date 1307227022 10800
# Node ID 1eb5a0e531bf733c6872b14e7a9c83a3a6afc96c
# Parent 83d76f6e0a3c884f135932564844bf1a0c32489d
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
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj
--- 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 @@
+
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Domain/Identification.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
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs
--- 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);
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs
--- 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
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs
--- 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
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Web/IdentityHelper.cs
--- 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
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs
--- 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; }
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Web/Views/Account/Register.cshtml
--- 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.")
-
-
-
+ @Html.EditorForModel()
+
+
+
}
diff -r 83d76f6e0a3c -r 1eb5a0e531bf Agendas/trunk/src/Agendas.Web/Web.config
--- 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 @@
-
+
-