Permalink
Browse files

Pulling the user name from Facebook

  • Loading branch information...
ZainRizvi committed Mar 25, 2016
1 parent f771c75 commit 0691694a15f38c7fb034feff0749724c9c60e25e
@@ -181,8 +181,11 @@ public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
// If the user does not have an account, then ask the user to create an account.
ViewData["ReturnUrl"] = returnUrl;
ViewData["LoginProvider"] = info.LoginProvider;
var email = info.ExternalPrincipal.FindFirstValue(ClaimTypes.Email);
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = email });
var name = info.ExternalPrincipal.FindFirstValue(ClaimTypes.Name);
return await ExternalLoginConfirmation(new ExternalLoginConfirmationViewModel { Email = email, UserName = name });
}
}
@@ -206,7 +209,7 @@ public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirma
{
return View("ExternalLoginFailure");
}
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
var result = await _userManager.CreateAsync(user);
if (result.Succeeded)
{
@@ -222,7 +225,7 @@ public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirma
}
ViewData["ReturnUrl"] = returnUrl;
return View(model);
return View("ExternalLoginConfirmation", model);
}
// GET: /Account/ConfirmEmail
@@ -47,9 +47,11 @@ public void ConfigureServices(IServiceCollection services)
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddIdentity<ApplicationUser, IdentityRole>(options => {
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._' ";
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
@@ -11,5 +11,9 @@ public class ExternalLoginConfirmationViewModel
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[EmailAddress]
public string UserName { get; set; }
}
}

0 comments on commit 0691694

Please sign in to comment.