/// <summary> /// Author: BOS Framework, Inc /// Description: Private method to fetch the data necessary to render the page /// </summary> /// <returns></returns> private async Task <dynamic> GetPageData() { try { var moduleOperations = HttpContext.Session.GetObject <List <Module> >("ModuleOperations"); Guid currentModuleId = new Guid(); try { currentModuleId = moduleOperations.Where(i => i.Code == "USERS").Select(i => i.Id).ToList()[0]; } catch (ArgumentNullException) { currentModuleId = Guid.Empty; } var currentOperations = moduleOperations.Where(i => i.Id == currentModuleId).Select(i => i.Operations).ToList()[0]; string operationsString = String.Join(",", currentOperations.Select(i => i.Code)); dynamic model = new ExpandoObject(); model.ModuleOperations = HttpContext.Session.GetObject <List <Module> >("ModuleOperations"); model.Operations = operationsString; model.CurrentModuleId = currentModuleId; model.Initials = User.FindFirst(c => c.Type == "Initials").Value.ToString(); if (User.FindFirst(c => c.Type == "Username") != null || User.FindFirst(c => c.Type == "Role") != null) { model.Username = User.FindFirst(c => c.Type == "Username").Value.ToString(); model.Roles = User.FindFirst(c => c.Type == "Role").Value.ToString(); } StringConversion stringConversion = new StringConversion(); var userList = await _bosAuthClient.GetUsersWithRolesAsync <User>(); if (userList != null && userList.IsSuccessStatusCode) { var updatedUserList = userList.Users.Select(c => { c.UpdatedId = stringConversion.EncryptString(c.Id.ToString()); return(c); }).ToList(); model.UserList = updatedUserList; } return(model); } catch (Exception ex) { Logger.LogException("Users", "GetPageData", ex); return(null); } }
public async Task ForcePasswordChange_returns_error_string_when_userid_is_invalid() { //Arrange var controller = new AuthController(_configuration, _contextAccessor, multitenantService); dynamic passwordInfo = new ExpandoObject(); StringConversion stringConversion = new StringConversion(); string userId = stringConversion.EncryptString(Guid.NewGuid().ToString()); passwordInfo.userId = userId; passwordInfo.password = "******"; JObject data = JObject.FromObject(passwordInfo); //Act var result = await controller.ForcePasswordChange(data); //Assert var errorMessage = Assert.IsType <string>(result); //Asserting that the return is a string Assert.Contains("Something went wrong.", errorMessage.ToString()); //Asserting that the returned message matches to the one mentioned }
private async Task <dynamic> GetPageData() { var modules = HttpContext.Session.GetObject <List <Module> >("Modules"); dynamic model = new ExpandoObject(); model.Modules = modules; if (User.FindFirst(c => c.Type == "Username") != null || User.FindFirst(c => c.Type == "Role") != null) { model.Username = User.FindFirst(c => c.Type == "Username").Value.ToString(); model.Roles = User.FindFirst(c => c.Type == "Role").Value.ToString(); } StringConversion stringConversion = new StringConversion(); var userList = await _bosAuthClient.GetUsersWithRolesAsync <User>(); if (userList.IsSuccessStatusCode) { var updatedUserList = userList.Users.Select(c => { c.UpdatedId = stringConversion.EncryptString(c.Id.ToString()); return(c); }).ToList(); model.UserList = updatedUserList; } return(model); }
public async Task ForcePasswordChange_returns_error_message_when_password_is_null() { //Arrange var controller = new AuthController(_bosAuthClient, _bosIAClient, _bosEmailClient, _configuration); dynamic passwordInfo = new ExpandoObject(); StringConversion stringConversion = new StringConversion(); string userId = stringConversion.EncryptString(Guid.NewGuid().ToString()); passwordInfo.userId = userId; passwordInfo.password = null; JObject data = JObject.FromObject(passwordInfo); //Act var result = await controller.ForcePasswordChange(data); //Assert var errorMessage = Assert.IsType <string>(result); //Asserting that the return is a string Assert.Contains("Something went wrong", errorMessage.ToString()); //Asserting that the returned message matches to the one mentioned }
/// <summary> /// Author: BOS Framework, Inc /// Description: Private method to fetch the data necessary to render the page /// </summary> /// <returns></returns> private async Task <dynamic> GetPageData() { try { //Checking if Sessions are enabled and non-null if (HttpContext != null && HttpContext.Session != null) { var moduleOperations = HttpContext.Session.GetObject <List <Module> >("ModuleOperations"); //This is the list of permitted modules and operations to the logged-in user Guid currentModuleId = new Guid(); // A new variable to save the current or selected module Id. This is being used, especially in the custom modules → more for the UI purposes try { currentModuleId = moduleOperations.Where(i => i.Code == "USERS").Select(i => i.Id).ToList()[0]; //Selecting the moduledD for MyProfile } catch { currentModuleId = Guid.Empty; } var operationsList = moduleOperations.Where(i => i.Id == currentModuleId).Select(i => i.Operations).ToList(); //Fetching the allowed operations in this module for the given user string operationsString = string.Empty; if (operationsList.Count > 0) { var currentOperations = operationsList[0]; operationsString = String.Join(",", currentOperations.Select(i => i.Code)); //Converting the list of operations to a string, so it can be used in the View } //Preparing the dynamic object that has data used for rendering the page dynamic model = new ExpandoObject(); model.ModuleOperations = moduleOperations; model.Operations = operationsString; model.CurrentModuleId = currentModuleId; //Checking for non-null claims object if (User != null) { model.Initials = User.FindFirst(c => c.Type == "Initials")?.Value.ToString(); model.Username = User.FindFirst(c => c.Type == "Username")?.Value.ToString(); model.Roles = User.FindFirst(c => c.Type == "Role")?.Value.ToString(); } StringConversion stringConversion = new StringConversion(); var userList = await _bosAuthClient.GetUsersWithRolesAsync <User>(); //Getting the list of all the users in the application using the BOS API if (userList != null && userList.IsSuccessStatusCode) { var updatedUserList = userList.Users.Select(c => { c.UpdatedId = stringConversion.EncryptString(c.Id.ToString()); return(c); }).ToList(); //Updating the user object with the encrypted userid, which will be used in the View and for passing into APIs from the view to the controller model.UserList = updatedUserList; } return(model); //Returning the mode with all the data that is required to render the page } else { return(null); } } catch (Exception ex) { Logger.LogException("Users", "GetPageData", ex); return(null); } }