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)); }
private async Task <User> FromExternalLoginAsync(UserInfo userInfo) { User existingUser = await _userRepository.GetUserByOAuthProviderAsync(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); } await _userRepository.SaveAsync(existingUser, true); } 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); await _userRepository.SaveAsync(ExceptionlessUser, true); return(ExceptionlessUser); } // Create a new user account or return an existing one. if (existingUser != null) { if (!existingUser.IsEmailAddressVerified) { existingUser.MarkEmailAddressVerified(); await _userRepository.SaveAsync(existingUser, true); } return(existingUser); } // Check to see if a user already exists with this email address. User user = !String.IsNullOrEmpty(userInfo.Email) ? await _userRepository.GetByEmailAddressAsync(userInfo.Email) : null; if (user == null) { if (!Settings.Current.EnableAccountCreation) { throw new ApplicationException("Account Creation is currently disabled."); } user = new User { FullName = userInfo.GetFullName(), EmailAddress = userInfo.Email }; user.Roles.Add(AuthorizationRoles.Client); user.Roles.Add(AuthorizationRoles.User); await AddGlobalAdminRoleIfFirstUserAsync(user); } user.MarkEmailAddressVerified(); user.AddOAuthAccount(userInfo.ProviderName, userInfo.Id, userInfo.Email); if (String.IsNullOrEmpty(user.Id)) { await _userRepository.AddAsync(user, true); } else { await _userRepository.SaveAsync(user, true); } return(user); }
private User AddExternalLogin(UserInfo userInfo) { ExceptionlessClient.Default.CreateFeatureUsage("External Login").AddTags(userInfo.ProviderName).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) { MarkEmailAddressVerified(existingUser); _userRepository.Save(existingUser); } return(existingUser); } // Check to see if a user already exists with this email address. bool isFirstUser = false; User user = !String.IsNullOrEmpty(userInfo.Email) ? _userRepository.GetByEmailAddress(userInfo.Email) : null; if (user == null) { if (!Settings.Current.EnableAccountCreation) { throw new ApplicationException("Account Creation is currently disabled."); } user = new User { FullName = userInfo.GetFullName(), EmailAddress = userInfo.Email }; user.Roles.Add(AuthorizationRoles.Client); user.Roles.Add(AuthorizationRoles.User); isFirstUser = AddGlobalAdminRoleIfFirstUser(user); } MarkEmailAddressVerified(user); user.AddOAuthAccount(userInfo.ProviderName, userInfo.Id, userInfo.Email); _userRepository.Save(user); if (isFirstUser && Settings.Current.WebsiteMode == WebsiteMode.Dev) { _dataHelper.CreateSampleOrganizationAndProject(user.Id); } return(user); }