예제 #1
0
 /// <summary>
 /// 退出登录
 /// 创建  毛枫  2015-4-21
 /// </summary>
 public static void LogOut()
 {
     WebHelperUtil.ClearCookie("AdminToken");
     WebHelperUtil.ClearCookie("AdminAuth");
     WebHelperUtil.ClearCookie("AdminLastLogTime");
     WebHelperUtil.ClearCookie("AdminUserLogin");
     WebHelperUtil.ClearCookie("A_AdminUser");
     ClearUserPower();
     //回到登陆页面
     PageContext.Redirect("/login.aspx");
 }
예제 #2
0
        /// <summary>
        /// 校验登入用户是否拥有页面权限
        /// 创建  毛枫  2015-4-21
        /// </summary>
        /// <param name="viewPower"></param>
        /// <returns></returns>
        public static bool CompareRole(string viewPower)
        {
            //HttpContext context = HttpContext.Current;

            List <T_POWERS> adminPowersList = new List <T_POWERS>();
            bool            result          = false;
            int             userId          = 0;
            string          userName        = string.Empty;

            if (HttpContext.Current.Session["A_Power"] == null)
            {
                //如果A_Power的Session是为空的话就首先判断当前用户是否登录
                if (IsLogIn(ref userId, ref userName))
                {
                    AdminUserModel user   = GetCurrentAdminUser();
                    string         A_Code = user.A_CODE;
                    //获取当前用户角色CODE
                    List <string> userRoleList = GetUserRole(A_Code);
                    foreach (string q in userRoleList)
                    {
                        //获取角色对应权限
                        adminPowersList.AddRange(GetUserPower(q));
                    }
                    //放入Session中
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                //存在Session
                string powerList = WebHelperUtil.SessionGet("A_Power");
                adminPowersList = powerList.toJsonObject <List <T_POWERS> >();
            }

            if (adminPowersList != null)
            {
                //将权限Model放入SESSION中
                string powerList = adminPowersList.toJson();
                WebHelperUtil.SessionAdd("A_Power", powerList, 60);
            }
            //判断登入用户有无页面权限
            if (adminPowersList.Any(qq => qq.P_NAME == viewPower))
            {
                result = true;
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// 功能描述:验证是否已登录
        /// 创建:  毛枫
        /// 2015年10月26日10:21:33
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="userName">用户名称</param>
        /// <returns>是否成功</returns>
        public static bool IsLogIn(ref int userId, ref string userName)
        {
            string tokenCookie   = WebHelperUtil.GetCookie("AdminToken");
            string authCookie    = WebHelperUtil.GetCookie("AdminAuth");
            string ckLastLogTime = WebHelperUtil.GetCookie("AdminLastLogTime");

            //验证是否存在登录状态cookie
            if (string.IsNullOrEmpty(tokenCookie))
            {
                return(false);
            }
            ////验证当前站点Session
            ////当前站点已登录,存在session
            AdminUserModel loginInfo = GetCurrentAdminUser();

            if (!string.IsNullOrEmpty(loginInfo.A_NAME))
            {
                userId   = Convert.ToInt32(loginInfo.A_ID);
                userName = loginInfo.A_NAME;
            }
            else
            {
                return(false);
            }
            //if (HttpContext.Current.Session["A_Id"] != null)
            //{
            //    userId = Convert.ToInt32(HttpContext.Current.Session["A_Id"]);
            //    userName = HttpContext.Current.Session["A_AdminName"].ToString();
            //}
            //else
            //{
            //    if (string.IsNullOrEmpty(authCookie))
            //    {
            //        return false;
            //    }
            //    if (!CheckAuthInfo(authCookie, ref userId, ref userName))
            //    {
            //        return false;
            //    }

            //}
            return(true);
        }
예제 #4
0
        /// <summary>
        /// 管理员登录
        /// 创建  毛枫  2015-4-21
        /// 修改  毛枫  2015-7-31
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool AdminLoginIn(string username, string password)
        {
            bool result = false;

            try
            {
                T_ADMIN admin = new T_ADMIN();
                admin = IsLoginFromSql(username, password);
                if (admin != null)
                {
                    #region Cookie和Session的设置
                    //System.Web.HttpContext.Current.Session["A_ID"] = admin.ID;
                    //System.Web.HttpContext.Current.Session["A_Code"] = admin.A_CODE;
                    //System.Web.HttpContext.Current.Session["A_TrueName"] = admin.A_TRUE_NAME;
                    //System.Web.HttpContext.Current.Session["A_AdminName"] = admin.A_NAME;
                    //System.Web.HttpContext.Current.Session.Timeout = 10800;
                    WebHelperUtil.SessionAdd("A_ID", admin.ID.ToString(), 60);
                    WebHelperUtil.SessionAdd("A_Code", admin.A_CODE, 60);
                    WebHelperUtil.SessionAdd("A_TrueName", admin.A_TRUE_NAME, 60);
                    WebHelperUtil.SessionAdd("A_AdminName", admin.A_NAME, 60);
                    ////生成用户模型
                    //System.Web.HttpContext.Current.Session["A_AdminUser"] = new AdminUserModel()
                    //{
                    //    A_ID = admin.ID,
                    //    A_CODE = admin.A_CODE,
                    //    A_NAME = admin.A_NAME,
                    //    A_CHINESE_NAME = admin.A_TRUE_NAME,
                    //};
                    string userModle = new AdminUserModel()
                    {
                        A_ID           = admin.ID,
                        A_CODE         = admin.A_CODE,
                        A_NAME         = admin.A_NAME,
                        A_CHINESE_NAME = admin.A_TRUE_NAME,
                    }.toJson();
                    //加密处理
                    userModle = EncryptUtil.Base64Encode(userModle);
                    WebHelperUtil.SetCookie("A_AdminUser", userModle, ExpiresDayCookiesSession);

                    //生成验证字符串cookie
                    string authStr = admin.ID + "^" + username.ToLower() + "^" + DateTime.Now.AddHours(2);
                    authStr = EncryptUtil.DESEncryptString(authStr);

                    //添加Cookie
                    WebHelperUtil.SetCookie("AdminToken", EncryptUtil.MD5(admin.ID.ToString(), 16), ExpiresDayCookiesSession);
                    WebHelperUtil.SetCookie("AdminAuth", authStr, ExpiresDayCookiesSession);
                    WebHelperUtil.SetCookie("AdminLastLogTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), ExpiresDayCookiesSession);
                    WebHelperUtil.SetCookie("AdminUserLogin", "login", ExpiresDayCookiesSession);
                    #endregion

                    LoginCommon.InsertAdminLoginLog(admin);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
        public void ProcessRequest(HttpContext context)
        {
            string url = WebHelperUtil.GetRequestString("url");//获取值一律使用代码库中的方法

            context.Response.Redirect(url);
        }