Example #1
0
 /// <summary>
 /// 判断管理员是否已经登录(解决Session超时问题)
 /// </summary>
 public bool IsAdminLogin()
 {
     //如果Session不为Null
     if (Session["admin_userid"] != null && Session["issystem"] != null && Session["Permissions"] != null)
     {
         return(true);
     }
     else
     {
         //检查Cookies
         string adminname = Utils.GetCookie("AdminName", "FZtouch"); //解密用户名
         string adminpwd  = Utils.GetCookie("AdminPwd", "FZtouch");
         if (adminname != "" && adminpwd != "")
         {
             adminname = DESEncrypt.Decrypt(adminname); //解密用户名
             AdminUserBLL bll  = new AdminUserBLL();
             AdminUser    item = bll.UserLogin(adminname, adminpwd);
             if (item != null)
             {
                 Session["admin_userid"] = item.Id;
                 Session["issystem"]     = item.IsSystem;
                 Session["Permissions"]  = bll.GetPermissionsByUserID(item.Id);
                 return(true);
             }
         }
     }
     return(false);
 }
        private void PageInit()
        {
            rpt_UserRole.DataSource = MenuBiz.GetMenuList(0);
            rpt_UserRole.DataBind();

            if (UserId != 0)
            {
                lbl_Permissions.Text = AdminUserUserBiz.GetUserNameById(UserId);
                string Permissions = AdminUserUserBiz.GetPermissionsByUserID(UserId);
                if (Permissions != string.Empty)
                {
                    foreach (RepeaterItem item in rpt_UserRole.Items)
                    {
                        Repeater rptRole   = (Repeater)item.FindControl("rptRole");   //子菜单repeater
                        CheckBox CheckBox1 = (CheckBox)item.FindControl("CheckBox1"); //大类别前的CheckBox
                        Label    lbl_id    = (Label)item.FindControl("lbl_id");       //大类别ID
                        if (Permissions.IndexOf("," + lbl_id.Text + ",") != -1)
                        {                                                             //如果存在此选项则选中复选框
                            CheckBox1.Checked = true;
                        }

                        #region 二级分类
                        foreach (RepeaterItem itemRole in rptRole.Items)
                        {
                            CheckBox    cbkrowone = (CheckBox)itemRole.FindControl("cbkrowone"); //子菜单前的CheckBox
                            HiddenField hfid      = (HiddenField)itemRole.FindControl("hfid");   //子菜单的ID
                            if (Permissions.IndexOf("," + hfid.Value + ",") != -1)
                            {                                                                    //如果存在此选项则选中复选框
                                cbkrowone.Checked = true;
                            }
                        }
                        #endregion
                    }

                    if (Permissions.IndexOf("Permissions_s1") != -1)
                    {
                        cbk_Permissions.Checked = true;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="UserPwd">密码</param>
        /// <returns>登录是否成功</returns>
        private bool UserLogin(string UserName, string UserPwd)
        {
            AdminUserBLL UserBiz = new AdminUserBLL();
            AdminUser    item    = UserBiz.UserLogin(UserName, UserPwd);

            if (item != null)
            {
                Session["AdminName"]    = UserName;
                Session["admin_userid"] = item.Id;
                Session["admin_show"]   = 1;
                Session["issystem"]     = item.IsSystem;
                Session["Permissions"]  = UserBiz.GetPermissionsByUserID(item.Id);
                UserBiz.UpdateUser(item.Id, Utils.GetTrueIPAddress());
                //写入Cookies
                Utils.WriteCookie("AdminName", "FZtouch", DESEncrypt.Encrypt(UserName));
                Utils.WriteCookie("AdminPwd", "FZtouch", UserPwd);
                return(true);
            }
            else
            {
                return(false);
            }
        }