public void SignOut(string userName) { if (!string.IsNullOrEmpty(userName)) //remove from ViewElementGrantedToUser { _userProService.RemoveOnlineUsers(userName); var userId = CustomMembershipProvider.GetUserIdCookie() ?? 0; UserViewElement userViewElement = null; if (_viewElementService.AppBase.ViewElementsGrantedToUser.TryGetValue(userId, out userViewElement)) { UserViewElement removedElement = null; _viewElementService.AppBase.ViewElementsGrantedToUser.TryRemove(userId, out removedElement); } } // Delete the authentication ticket and sign out. FormsAuthentication.SignOut(); // Clear authentication cookie CustomMembershipProvider.ClearMembershipCookie(FormsAuthentication.FormsCookieName); CustomMembershipProvider.ClearMembershipCookie(CustomMembershipProvider.UserIdCookieName); CustomMembershipProvider.ClearMembershipCookie(CustomMembershipProvider.PassCodeCookieName); Core.Cmn.AppBase.OnAfterUserSignOut(EventArgs.Empty); //if (redirectToLoginPage) //FormsAuthentication.RedirectToLoginPage(); }
public static bool HasCurrentUserAccess(int userId, string url = null, string uniqueName = null) { bool hasAcces = false; if (url == null && uniqueName == null) { throw new Exception("url & also uniqueName can't be null."); } UserViewElement currentUser = null; if (AppBase._viewElementsGrantedToUser.TryGetValue(userId, out currentUser)) { if (uniqueName == null) { var tempUrl = url.StartsWith("api/") ? url.ToLower().Remove(0, 4) : url.ToLower(); var viewElementGrantedToUser = currentUser.ViewElements; hasAcces = viewElementGrantedToUser.Any(element => element.Url.ToLower() == tempUrl.ToLower()); } else { var viewElementGrantedToUser = currentUser.ViewElements; hasAcces = viewElementGrantedToUser.Any(element => $"{element.ConceptualName.ToLower()}#{element.Url.ToLower()}" == uniqueName.ToLower()); } } else { hasAcces = false; } return(hasAcces); }
public bool HasRoleAccess(int userId, string uniqueName, string urlParam = "") { UserViewElement currentUser = null; var viewElements = ViewElementRoleService.GetViewElementGrantedToUserByUserId(userId); currentUser = new UserViewElement { UserId = userId, ViewElements = viewElements }; appBase.ViewElementsGrantedToUser.TryAdd(userId, currentUser); var accessVElement = currentUser.ViewElements; foreach (var item in accessVElement) { if (!string.IsNullOrEmpty(uniqueName)) { if (HasRequestedUrlAccessInViewElement(item, uniqueName)) { return(true); } } } return(false); }
public void SetViewElementGrantedToUser(UserProfile userProf) { var viewElementGrantedToUser = GetViewElementGrantedToUserByUserId(userProf.Id); UserViewElement currentUser = null; if (!AppBase.ViewElementsGrantedToUser.TryGetValue(userProf.Id, out currentUser)) { AppBase.ViewElementsGrantedToUser.TryAdd(userProf.Id, new UserViewElement { UserId = userProf.Id, ViewElements = viewElementGrantedToUser }); } }
public static ViewElementInfo GetMenuItemPathByUniqueName(int userId, string uniqueName) { var commonViewElement = AppBase._viewElementsGrantedToAnonymousUser.ViewElements .FirstOrDefault(element => element.ConceptualName.Split('#')[0].ToLower() == uniqueName.ToLower()); if (commonViewElement != null) { return(commonViewElement); } UserViewElement currentUser = null; if (AppBase._viewElementsGrantedToUser != null && AppBase._viewElementsGrantedToUser.TryGetValue(userId, out currentUser)) { var viewElement = currentUser.ViewElements .FirstOrDefault(element => element.ConceptualName.Split('#')[0].ToLower() == uniqueName.ToLower()); return(viewElement); } return(null); //throw new Exception("The entered url does not exist in any Role"); }