private void initLeftData()
    {
        LoginUserVO user = m_SessionHelper.LoginUser;

        if (user != null)
        {
            //     lblUserId.Text = user.UserId;
            //快取載入
            user = UserMenuFuncContainer.GetInstance().GetUser(user.UserId);

            //user = m_AuthService.GetLoginUserByIdNoLazy(user.UserId);

            IList <LoginRoleVO> roleList = user.LoginRoleList;

            List <string> roleStr = new List <string>();

            if (roleList != null && roleList.Count > 0)
            {
                foreach (LoginRoleVO role in roleList)
                {
                    roleStr.Add(role.RoleName);
                }
            }

            //     lblRole.Text = String.Join(",", roleStr.ToArray());
        }
        else
        {
            Response.Redirect(UIHelper.LOGIN_PAGE_MANAGER, false);
            return;
        }
    }
示例#2
0
        public void Test_UserMenuFuncContainer()
        {
            //清除快取
            UserMenuFuncContainer.GetInstance().ReloadAllMenu();

            UserMenuFuncContainer.GetInstance().GetUser("admin");
            UserMenuFuncContainer.GetInstance().GetUser("admin");
        }
    private void initMenu()
    {
        LoginUserVO user = m_SessionHelper.LoginUser;

        //快取載入
        UserMenuFuncContainer userContainer = UserMenuFuncContainer.GetInstance();

        if (user == null)
        {
            Response.Redirect(UIHelper.LOGIN_PAGE_MANAGER, false);
            return;
        }
        user = userContainer.GetUser(user.UserId);

        //TreeveiwService tvService = new TreeveiwService();

        IList <MenuFuncVO> menuFuncList = m_AuthService.GetTopMenuFunc(user, userContainer.AllMenu, userContainer.RoleDic);

        foreach (MenuFuncVO menu in menuFuncList)
        {
            TreeNode treeNode = new TreeNode(menu.MenuFuncName, menu.MenuFuncId.ToString(), "", "welcome.aspx", "mainfrm");

            if (menu.SubFuncs.Count > 0)
            {
                foreach (MenuFuncVO subMenu in menu.SubFuncs)
                {
                    if (string.IsNullOrEmpty(subMenu.Note) || subMenu.Note.ToLower().IndexOf("_sub") == -1)
                    {
                        TreeNode subTreeNode = new TreeNode(subMenu.MenuFuncName, null, null, "~/" + subMenu.MainPath, "mainfrm");
                        treeNode.ChildNodes.Add(subTreeNode);
                    }
                }
            }

            tvMenu.Nodes.Add(treeNode);
        }

        if (tvMenu.Nodes != null && tvMenu.Nodes.Count > 0)
        {
            tvMenu.Nodes[0].Expand();
            tvMenu.DataBind();
        }
    }
    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        string      selectedRole = ddlRole.SelectedValue;
        LoginRoleVO role         = m_AuthService.GetLoginRoleByIdNoLazy(int.Parse(selectedRole));

        foreach (GridViewRow row in gvAuth.Rows)
        {
            CheckBox    ckAuth = (CheckBox)row.FindControl("ckIsAuth");
            HiddenField hdnId  = (HiddenField)row.FindControl("hdnId");

            if (ckAuth.Checked == true)
            {
                if (role.MenuFuncList == null)
                {
                    role.MenuFuncList = new List <MenuFuncVO>();
                }

                MenuFuncVO theFunc = m_AuthService.GetMenuFuncById(int.Parse(hdnId.Value));

                if (!m_AuthService.RoleHasMenuRight(role, theFunc))
                {
                    role.MenuFuncList.Add(theFunc);
                }
            }
            else
            {
                MenuFuncVO theFunc = m_AuthService.GetMenuFuncById(int.Parse(hdnId.Value));

                if (m_AuthService.RoleHasMenuRight(role, theFunc))
                {
                    //role.MenuFuncList.Remove(theFunc);
                    role.MenuFuncList.Remove(role.MenuFuncList.Where(p => p.MenuFuncId == int.Parse(hdnId.Value)).ToList()[0]);
                }
            }
        }

        m_AuthService.UpdateLoginRole(role);
        m_WebLogService.AddSystemLog(MsgVO.Action.修改, role);

        UserMenuFuncContainer.GetInstance().ResetAll();

        lblMsg.Text = MsgVO.UPDATE_OK;
    }
    protected void Button3_Click(object sender, ImageClickEventArgs e)
    {
        string             userId        = ddlUser.SelectedValue;
        LoginUserVO        user          = m_AuthService.GetLoginUserByIdNoLazy(userId);
        List <LoginRoleVO> loginRoleList = new List <LoginRoleVO>();

        foreach (ListItem item in lbxHadRole.Items)
        {
            loginRoleList.Add(m_AuthService.GetLoginRoleById(int.Parse(item.Value)));
        }

        user.LoginRoleList = loginRoleList;

        m_AuthService.UpdateLoginUser(user);
        m_WebLogService.AddSystemLog(MsgVO.Action.修改, user);

        //更新快取
        UserMenuFuncContainer.GetInstance().ResetAll();

        lblMsg.Text = MsgVO.UPDATE_OK;
    }
    /// <summary>
    /// 檢查權限
    /// </summary>
    /// <param name="application"></param>
    /// <param name="uri"></param>
    /// <param name="rawUrl"></param>
    private void CheckAuth(HttpApplication application, Uri uri, string rawUrl)
    {
        SessionHelper sHelper = new SessionHelper();

        LoginUserVO loginUser = sHelper.LoginUser;

        string applicationPath = application.Request.ApplicationPath;

        string mamagePath = String.IsNullOrEmpty(applicationPath) ? "/admin" : applicationPath + "/admin";

        mamagePath = mamagePath.Replace("//", "/");

        if (rawUrl.StartsWith(mamagePath) == true)
        {
            AuthFactory  authFactory = new AuthFactory();
            IAuthService authService = authFactory.GetAuthService();

            if (loginUser == null)
            {
                toLoginPage(application.Response);
                return;
            }

            string userId = loginUser.UserId;

            //判斷只有主路徑是否有權限
            //if (!PathHasRight(UserMenuFuncContainer.GetInstance().GetUser(userId), uri, UserMenuFuncContainer.GetInstance().PathFunc))
            //{
            //    toLoginNoAuthPage(application.Response);
            //}


            //判斷所有路徑是否有權限
            if (!authService.PathHasAuth(UserMenuFuncContainer.GetInstance().GetUser(userId), uri))
            {
                toLoginNoAuthPage(application.Response);
            }
        }
    }
    private void doLogin(string id, string pw)
    {
        //帳號皆改為小寫
        if (!string.IsNullOrEmpty(id))
        {
            id = id.ToLower();
        }

        LoginUserVO loginUser = m_AuthService.Login(id, pw);

        if (loginUser != null)
        {
            SessionHelper sHelper = new SessionHelper();

            sHelper.LoginUser = loginUser;
            sHelper.IsAdmin   = m_AuthService.IsAdmin(loginUser);
            //sHelper.LoginUserBelongToBranchNo = loginUser.BelongToBranch[0].BranchNo;
            //加入log
            webLogService.AddSystemLogLogin(loginUser.UserId);

            //NHibernateUtil.Initialize(loginUser.BelongRoles);

            //清除快取
            UserMenuFuncContainer.GetInstance().ReloadAllMenu();

            //HttpHelper httpHelper = new HttpHelper();
            //string referer = httpHelper.GetReferer(HttpContext.Current);

            Response.Redirect("~/admin/index.aspx", false);

            return;
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJSAndRedirect(MsgVO.LOGIN_ERROR, "Login.aspx"), false);
        }
    }