示例#1
0
        public static clsSecurity GetLoginUser()
        {
            clsSecurity oUser = HttpContext.Current.Session[Constants.SessionUser] as clsSecurity;

            if (oUser == null)
            {
                HttpContext.Current.Response.Redirect(Constants.HomeUrl);
            }
            return(oUser);
        }
示例#2
0
        public static clsSecurity GetUser(decimal logID, int orgID, string[] appID, string userName)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.DebugFormat("Start GetUser(). Param Received : {0}" +
                            "       LogID : {1}{0}" +
                            "       OrgID : {2}{0}" +
                            "       AppID : {3}{0}" +
                            "       Username : {4}{0}", Environment.NewLine, logID, orgID, appID, userName);

            try
            {
                clsSecurity oUser            = null;
                DataTable   dtUserPermission = new DataTable();

                for (int i = 0; i < appID.Length; i++)
                {
                    DataTable dtTemp = GetUserPermission(logID, orgID, appID[i], userName);

                    dtUserPermission.Merge(dtTemp);
                }

                log.DebugFormat("There are {0} data Permission for username {1}", dtUserPermission.Rows.Count, userName);

                if (dtUserPermission.Rows.Count > 0)
                {
                    log.DebugFormat("Create object clsSecurity for username {0} and Total Page Allowed {1}", userName, dtUserPermission.Rows.Count);

                    oUser                = new clsSecurity();
                    oUser.UserName       = dtUserPermission.Rows[0]["UserName"].ToString();
                    oUser.UserPermission = dtUserPermission;

                    oUser.UserRoles = new List <string>();
                    foreach (DataRow row in dtUserPermission.Rows)
                    {
                        oUser.UserRoles.Add(row["RoleName"].ToString());
                    }
                }

                log.DebugFormat("End GetUser().");

                return(oUser);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Error GetUser(). Message : {0}", ex.Message);
                throw;
            }

            log.DebugFormat("End GetUser().");
        }
示例#3
0
        public static bool ValidateUserRole(string userRole)
        {
            clsSecurity oUser = Helper.GetLoginUser();

            return(oUser.UserRoles.Contains(userRole, StringComparer.InvariantCultureIgnoreCase));
        }