info.ProviderKey, isPersistent: false, bypassTwoFactor: true);
if (signInResult.Succeeded)
{
return LocalRedirect(returnUrl);
}
else
{
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
var phone = info.Principal.FindFirstValue(ClaimTypes.MobilePhone);
if (info.LoginProvider.ToString() == "Google")
{
//когда гугл все хорошо потому что аккаунт это и есть по сути имейл
if (email != null)
{
var user = await _userManager.FindByEmailAsync(email);
if (user == null)
{
user = new User
{
UserName = info.Principal.FindFirstValue(ClaimTypes.Email),
Email = info.Principal.FindFirstValue(ClaimTypes.Email),
FirstName = info.Principal.FindFirstValue(ClaimTypes.GivenName),
LastName = info.Principal.FindFirstValue(ClaimTypes.Surname),
ImagePath = "default.png",
UserProfile = new UserProfile
{
}
};
await _userManager.CreateAsync(user);
}
await _userManager.AddLoginAsync(user, info);
await _signInManager.SignInAsync(user, isPersistent: false);
return LocalRedirect(returnUrl);
}
}
else if(info.LoginProvider.ToString() == "Facebook")
{
/*
в фейсбуке когда аккаунт зарегистрирован на почту то хорошо а когда на мобильный телефон проблема.Як мне вытянуть телефон с Claims*/
var user = await _userManager.FindByNameAsync(email ?? phone);
if (email != null || phone != null)
{
if (user == null)
{
user = new User
{
UserName = email ?? phone,
Email = email,
PhoneNumber = phone,
FirstName = info.Principal.FindFirstValue(ClaimTypes.GivenName),
LastName = info.Principal.FindFirstValue(ClaimTypes.Surname),
ImagePath = "default.png",
UserProfile = new UserProfile(),
};
await _userManager.CreateAsync(user);
}
await _userManager.AddLoginAsync(user, info);
await _signInManager.SignInAsync(user, isPersistent: false);
return LocalRedirect(returnUrl);
}
}
return View("Error");
}