public void CanGetLoggedInUserDetails() { //Arrange UserAuthentication userAuthenticationModel = new UserAuthentication(); userAuthenticationModel = Builder <UserAuthentication> .CreateListOfSize(1).Build().ToList().FirstOrDefault(); string userData = JsonConvert.SerializeObject(userAuthenticationModel); List <Claim> claims = new List <Claim> { new Claim(ClaimTypes.Name, userAuthenticationModel.UserName), new Claim(ClaimTypes.NameIdentifier, userAuthenticationModel.UserId.ToString()), new Claim(ClaimTypes.Authentication, "Form"), new Claim("UserId", userAuthenticationModel.UserId.ToString()), new Claim("AuthenticationGUID", userAuthenticationModel.AuthenticationGUID), new Claim("LoggedOn", userAuthenticationModel.LoggedOn.ToString()), new Claim("AuthenticationExpiresOn", "AuthenticationExpiresOn", userAuthenticationModel.AuthenticationExpiresOn.ToString()), new Claim(ClaimTypes.UserData, userData), }; var identityClaims = new ClaimsIdentity(claims); ClaimsPrincipal principal = new ClaimsPrincipal(identityClaims); //Act var userAuthentication = WebAppMVCExtensions.GetLoggedInUserDetails(principal); //Assert Assert.AreEqual(userAuthenticationModel.UserName, userAuthentication.UserName); }
public async ValueTask <IActionResult> UpdateUserAccountLockedStatusAsync(long userId, bool isLocked) { dynamic ajaxReturn = new JObject(); UserAuthentication userAuthenticationModel = new UserAuthentication(); userAuthenticationModel = WebAppMVCExtensions.GetLoggedInUserDetails(this.User); var isUpdateSuccess = await this._userManagementService.UpdateUserAccountLockedStatusAsync(userId, isLocked, userAuthenticationModel.UserId); if (isUpdateSuccess && isLocked) { ajaxReturn.Status = "Success"; ajaxReturn.Message = "User account locked successfully"; } else if (isUpdateSuccess && !isLocked) { ajaxReturn.Status = "Success"; ajaxReturn.Message = "User account un-locked successfully"; } else { ajaxReturn.Status = "Error"; ajaxReturn.Message = "Error occured"; } return(this.Json(ajaxReturn)); }
public async ValueTask <IActionResult> EditUserRolesAsync(List <UserRoleViewModel> userRolesViewModel) { dynamic ajaxReturn = new JObject(); List <UserRole> userRoles = new List <UserRole>(); userRoles = this._mapper.Map <List <UserRole> >(userRolesViewModel); var userAuthenticationModel = WebAppMVCExtensions.GetLoggedInUserDetails(this.User); var isEditUserRoleSuccess = await this._userManagementService.EditUserRolesAsync(userRoles, userAuthenticationModel.UserId); ajaxReturn.Status = "Success"; ajaxReturn.Message = "User role changed sucessfully."; return(this.Json(ajaxReturn)); }
public async ValueTask <IActionResult> UpdateUserAccountDetailsAsync(UpdateUserAccountViewModel updateUserAccountViewModel) { dynamic ajaxReturn = new JObject(); User user = new User(); var userAuthenticationModel = WebAppMVCExtensions.GetLoggedInUserDetails(this.User); user = this._mapper.Map <User>(updateUserAccountViewModel); user.ModifiedBy = userAuthenticationModel.UserId; var isUpdateSuccess = await this._userManagementService.UpdateUserAccountDetailsAsync(user); if (isUpdateSuccess) { ajaxReturn.Status = "Success"; ajaxReturn.Message = "User details saved successfully"; } else { ajaxReturn.Status = "Error"; ajaxReturn.Message = "Error occured"; } return(this.Json(ajaxReturn)); }