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)); }
public IHttpActionResult RemoveExternalLogin(string providerName, string providerUserId) { if (String.IsNullOrEmpty(providerName) || String.IsNullOrEmpty(providerUserId)) { return(BadRequest("Invalid Provider Name or Provider User Id.")); } if (ExceptionlessUser.OAuthAccounts.Count <= 1 && String.IsNullOrEmpty(ExceptionlessUser.Password)) { return(BadRequest("You must set a local password before removing your external login.")); } if (ExceptionlessUser.RemoveOAuthAccount(providerName, providerUserId)) { _userRepository.Save(ExceptionlessUser); } return(Ok()); }
public IHttpActionResult RemoveExternalLogin(string providerName, [NakedBody] string providerUserId) { if (String.IsNullOrEmpty(providerName) || String.IsNullOrEmpty(providerUserId)) { return(BadRequest("Invalid Provider Name or Provider User Id.")); } if (ExceptionlessUser.OAuthAccounts.Count <= 1 && String.IsNullOrEmpty(ExceptionlessUser.Password)) { return(BadRequest("You must set a local password before removing your external login.")); } if (ExceptionlessUser.RemoveOAuthAccount(providerName, providerUserId)) { _userRepository.Save(ExceptionlessUser); } ExceptionlessClient.Default.CreateFeatureUsage("Remove External Login").AddTags(providerName).AddObject(ExceptionlessUser).Submit(); return(Ok()); }
public async Task <IHttpActionResult> RemoveExternalLoginAsync(string providerName, [NakedBody] string providerUserId) { if (String.IsNullOrWhiteSpace(providerName) || String.IsNullOrWhiteSpace(providerUserId)) { _logger.Error().Message("Remove external login failed for \"{0}\": Invalid Provider Name or Provider User Id.", ExceptionlessUser.EmailAddress).Tag("External Login", providerName).Identity(ExceptionlessUser.EmailAddress).Property("User", ExceptionlessUser).Property("Provider User Id", providerUserId).SetActionContext(ActionContext).Write(); return(BadRequest("Invalid Provider Name or Provider User Id.")); } if (ExceptionlessUser.OAuthAccounts.Count <= 1 && String.IsNullOrEmpty(ExceptionlessUser.Password)) { _logger.Error().Message("Remove external login failed for \"{0}\": You must set a local password before removing your external login.", ExceptionlessUser.EmailAddress).Tag("External Login", providerName).Identity(ExceptionlessUser.EmailAddress).Property("User", ExceptionlessUser).Property("Provider User Id", providerUserId).SetActionContext(ActionContext).Write(); return(BadRequest("You must set a local password before removing your external login.")); } if (ExceptionlessUser.RemoveOAuthAccount(providerName, providerUserId)) { await _userRepository.SaveAsync(ExceptionlessUser, true); } _logger.Info().Message("\"{0}\" removed an external login: \"{1}\"", ExceptionlessUser.EmailAddress, providerName).Tag("External Login", providerName).Identity(ExceptionlessUser.EmailAddress).Property("User", ExceptionlessUser).SetActionContext(ActionContext).Write(); return(Ok()); }
public IHttpActionResult RemoveExternalLogin(string providerName, [NakedBody] string providerUserId) { if (String.IsNullOrEmpty(providerName) || String.IsNullOrEmpty(providerUserId)) { Log.Error().Message("Remove external login failed for \"{0}\": Invalid Provider Name or Provider User Id.", ExceptionlessUser.EmailAddress).Tag("External Login", providerName).Property("User", ExceptionlessUser).Property("Provider User Id", providerUserId).ContextProperty("HttpActionContext", ActionContext).Write(); return(BadRequest("Invalid Provider Name or Provider User Id.")); } if (ExceptionlessUser.OAuthAccounts.Count <= 1 && String.IsNullOrEmpty(ExceptionlessUser.Password)) { Log.Error().Message("Remove external login failed for \"{0}\": You must set a local password before removing your external login.", ExceptionlessUser.EmailAddress).Tag("External Login", providerName).Property("User", ExceptionlessUser).Property("Provider User Id", providerUserId).ContextProperty("HttpActionContext", ActionContext).Write(); return(BadRequest("You must set a local password before removing your external login.")); } if (ExceptionlessUser.RemoveOAuthAccount(providerName, providerUserId)) { _userRepository.Save(ExceptionlessUser); } Log.Info().Message("\"{0}\" removed an external login: \"{1}\"", ExceptionlessUser.EmailAddress, providerName).Tag("External Login", providerName).Property("User", ExceptionlessUser).ContextProperty("HttpActionContext", ActionContext).Write(); return(Ok()); }
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); }