public async Task <IResponse> FacebookSignIn([FromBody] FacebookLoginModel facebookLoginModel) { ExternalLoginResponse externalLoginResponse = new ExternalLoginResponse(); externalLoginResponse.IsModelValid = ModelState.IsValid; if (ModelState.IsValid) { FacebookDataModel facebookData = await FacebookAPI.GetUserLoginData(facebookLoginModel.AccessToken); ExternalLoginInfo info = CustomExternalLoginInfo.FromLoginModel("Facebook", facebookData); var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, true); if (result.Succeeded) { _logger.LogInformation("User logged in"); } externalLoginResponse.IsRegistered = result.Succeeded; externalLoginResponse.Result = result; } else { externalLoginResponse.Errors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)); } return(externalLoginResponse); }
public async Task <IResponse> GoogleSignIn([FromBody] GoogleLoginModel googleLoginModel) { ExternalLoginResponse externalLoginResponse = new ExternalLoginResponse(); externalLoginResponse.IsModelValid = ModelState.IsValid; if (ModelState.IsValid) { GoogleDataModel googleData = await GoogleAPI.GetUserLoginData(googleLoginModel.AccessToken); ExternalLoginInfo info = CustomExternalLoginInfo.FromLoginModel("Google", googleData); var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, true); externalLoginResponse.IsRegistered = result.Succeeded; externalLoginResponse.Result = result; } else { externalLoginResponse.Errors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)); } return(externalLoginResponse); }
public async Task <IResponse> GoogleRegister([FromBody] GoogleRegisterModel googleRegisterModel) { ExternalLoginResponse externalLoginResponse = new ExternalLoginResponse(); externalLoginResponse.IsModelValid = ModelState.IsValid; if (ModelState.IsValid) { GoogleDataModel googleData = await GoogleAPI.GetUserLoginData(googleRegisterModel.AccessToken); ExternalLoginInfo info = CustomExternalLoginInfo.FromLoginModel("Google", googleData); Account account = new Account { UserName = googleRegisterModel.Username, Email = googleData.Email }; var result = await _userManager.CreateAsync(account); if (result.Succeeded) { result = await _userManager.AddLoginAsync(account, info); account.SetUpPoints(_context); await _context.SaveChangesAsync(); if (result.Succeeded) { await _signInManager.SignInAsync(account, true); } } externalLoginResponse.CreateResult = result; externalLoginResponse.Errors = result.Errors.Select(x => x.Description); } else { externalLoginResponse.Errors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)); } return(externalLoginResponse); }