private User AddExternalLogin(UserInfo userInfo) { ExceptionlessClient.Default.CreateFeatureUsage("External Login").AddObject(userInfo).Submit(); User existingUser = _userRepository.GetUserByOAuthProvider(userInfo.ProviderName, userInfo.Id); // Link user accounts. if (ExceptionlessUser != null) { if (existingUser != null) { if (existingUser.Id != ExceptionlessUser.Id) { // Existing user account is not the current user. Remove it and we'll add it to the current user below. if (!existingUser.RemoveOAuthAccount(userInfo.ProviderName, userInfo.Id)) return null; _userRepository.Save(existingUser); } else { // User is already logged in. return ExceptionlessUser; } } // Add it to the current user if it doesn't already exist and save it. ExceptionlessUser.AddOAuthAccount(userInfo.ProviderName, userInfo.Id, userInfo.Email); _userRepository.Save(ExceptionlessUser); return ExceptionlessUser; } // Create a new user account or return an existing one. if (existingUser != null) { if (!existingUser.IsEmailAddressVerified) { existingUser.IsEmailAddressVerified = true; _userRepository.Save(existingUser); } return existingUser; } // Check to see if a user already exists with this email address. User user = !String.IsNullOrEmpty(userInfo.Email) ? _userRepository.GetByEmailAddress(userInfo.Email) : null; if (user == null) { user = new User { FullName = userInfo.GetFullName(), EmailAddress = userInfo.Email }; AddGlobalAdminRoleIfFirstUser(user); } user.IsEmailAddressVerified = true; user.AddOAuthAccount(userInfo.ProviderName, userInfo.Id, userInfo.Email); return _userRepository.Save(user); }