public async Task <string> Login(GoogleUserDataDto userInfo) { var user = _userRepository.GetUserByEmail(Dto.EmailType.LOGIN, userInfo.Email); if (user != null) { if (!user.GoogleVerified) { user.GoogleEmail = userInfo.Email; if (user.FacebookVerified) { user.GoogleVerified = true; } else { return(null); } } } else { user = _userRepository.GetUserByEmail(Dto.EmailType.GOOGLE, userInfo.Email); if (user == null) { await _userRepository.CreateUser(new User { FirstName = userInfo.GivenName, LastName = userInfo.FamilyName, Email = userInfo.Email, PictureUrl = userInfo.ImageUrl, FacebookVerified = false, GoogleVerified = false, GoogleEmail = userInfo.Email, FacebookEmail = null }); _userRepository.CreateUnauthorizedUser(new UnauthorizedUser { Email = userInfo.Email }); return(null); } if (!user.GoogleVerified) { return(null); } } return(await GenerateJwt(user)); }
public async Task <IActionResult> GoogleLogin([FromBody] GoogleUserDataDto userData) { var jwt = await _googleIdentity.Login(userData); if (jwt != null) { AddJwtToCookie(jwt); return(Ok(jwt)); } else { return(Unauthorized()); } }