public UserLookupResult GetCurrentUser(string currentUserName) { try { if (string.IsNullOrEmpty(currentUserName)) { return(UserLookupResult.Empty); } var identityUser = _identityProvider.FindUser(currentUserName).Result; if (identityUser == null) { return(UserLookupResult.Empty); } var userProfile = _clientAppRepo.GetUser(identityUser.Email); return(UserLookupResult.ForUser(userProfile, _httpContextAccessor.HttpContext.User)); } catch (SqlException) { //Gulp. Just return the empty result } return(UserLookupResult.Empty); }
public async Task CreateIdentityUsers() { try { foreach (var user in _users) { var identityUser = await _identityProvider.FindUser(user.Key); if (identityUser != null) { return; } _log.Debug($"Adding user: {user.Value} to asp net security."); if (await _identityProvider.CreateUser( user.Key, user.Value.Email, user.Value.Password, confirm: true)) { identityUser = await _identityProvider.FindUser(user.Key); var roles = new string[] { }; if (user.Value.Admin) { roles = new string[] { "Administrator" }; } _log.Debug($"Adding user: {user.Value} to roles: {string.Join(",", roles)} in asp net security."); await _identityProvider.AddToRoles(identityUser.Id, roles); } } } catch (Exception ex) { _log.Error(ex); } }