private User UpdateUserWithGoogleAuth(IdentityProviderAuthResponse auth) { GoogleUserInfo userInfo = _googleAPIs.GetUserInfo(auth.AccessToken).Result; string newAuthCode = AuthCodeUtility.GenerateAuthCode(); var updatedUser = _collection.FindOneAndUpdate( new FilterDefinitionBuilder <User>().Where(x => x.EmailAddress == auth.EmailAddress), new UpdateDefinitionBuilder <User>().Set(x => x.GoogleAuth, auth) .Set(x => x.FirstName, userInfo.FirstName) .Set(x => x.LastName, userInfo.LastName) .Set(x => x.AuthCode, newAuthCode) ); updatedUser.GoogleAuth = auth; updatedUser.AuthCode = newAuthCode; return(updatedUser); }
private User InsertUserWithGoogleAuth(IdentityProviderAuthResponse auth) { GoogleUserInfo userinfo = _googleAPIs.GetUserInfo(auth.AccessToken).Result; var newUser = new User(); newUser.FirstName = userinfo.FirstName; newUser.LastName = userinfo.LastName; newUser.Roles = new List <string>() { RolesEnum.None.ToString() }; newUser.EmailAddress = userinfo.Email; newUser.GoogleAuth = auth; newUser.AuthCode = AuthCodeUtility.GenerateAuthCode(); _collection.InsertOne(newUser); return(newUser); }