Exemplo n.º 1
0
        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <returns>用户对象</returns>
        public static MStaffInfo GetUser()
        {
            MStaffInfo modelStaff = HttpContext.Current.Session["$safeprojectname$_UserInfo"] as MStaffInfo;
            if (HttpContext.Current.Session["$safeprojectname$_UserInfo"] != null)
            {
                return HttpContext.Current.Session["$safeprojectname$_UserInfo"] as MStaffInfo;
            }

            TrackID.GetInstance(HttpContext.Current.User.Identity.Name);
            UserLoginServiceHelper.UserLoginServiceHelper userHelper = new UserLoginServiceHelper.UserLoginServiceHelper();
            MStaffInfo staff = userHelper.GetStaffInfoModel(HttpContext.Current.User.Identity.Name);
            HttpContext.Current.Session["$safeprojectname$_UserInfo"] = modelStaff;
            return modelStaff;
        }
Exemplo n.º 2
0
        /// <summary>
        /// GetUserMenus
        /// </summary>
        /// <param name="htmlHelper">htmlHelper</param>
        /// <param name="menu">menu</param>
        /// <returns>MvcHtmlString</returns>
        public static MvcHtmlString GetUserMenus(this HtmlHelper htmlHelper, string menu)
        {
            string webName = "您的网站名称";
            MStaffInfo mstaffInfo = HttpContext.Current.Session["$safeprojectname$_UserInfo"] as MStaffInfo;
            TrackIdManager.GetInstance(mstaffInfo.Staff_id);
            UserLoginServiceHelper.UserLoginServiceHelper userHelper = new UserLoginServiceHelper.UserLoginServiceHelper();

            // 获取菜单并放入session
            DataTable dtpower = null;

            var sessionName = "deptPower|$safeprojectname$Module_Menu";

            if (HttpContext.Current.Session[sessionName] != null)
            {
                dtpower = HttpContext.Current.Session[sessionName] as DataTable;
            }

            if (dtpower == null)
            {
                dtpower = userHelper.GetStaffPower(mstaffInfo.StaffType, mstaffInfo.Staff_id, mstaffInfo.Department_id, webName).Tables[0];
            }

            HttpContext.Current.Session[sessionName] = dtpower;

            DataRow[] mainMenu = dtpower.Select(" Node_Type = '-1' and IsMenu=1 ", "NodeSort");
            StringBuilder sb = new StringBuilder(2048);
            string node_Code = string.Empty;
            string title = string.Empty;
            string urlpage = string.Empty;
            string target = string.Empty;

            string token = HttpContext.Current.Session["Token"] as string;

            // 菜单展示
            string[] showMenuParam = null;

            showMenuParam = menu.Split('-');
            for (int i = 0; i < mainMenu.Length; i++)
            {
                node_Code = mainMenu[i]["Node_Code"].ToString();
                title = mainMenu[i]["Node_Name"].ToString();
                ////获得菜单项
                DataRow[] subMenu = dtpower.Select(string.Format(" PNode_Code='{0}' and IsMenu=1", node_Code), "NodeSort");
                ////添加菜单显示
                if (node_Code == "01" || (subMenu != null && subMenu.Length > 0))
                {
                    char[] visibledMenu = mainMenu[i]["visibled_Flag"].ToString().PadLeft(4, '0').ToCharArray();
                    if (visibledMenu[mstaffInfo.StaffType - 1] == '1')
                    {
                        sb.AppendFormat("<li><a href=\"#\" class=\"buy\" rel=\"buy\"><em></em>{0}</a>", title);

                        if (showMenuParam.Length > 1)
                        {
                            if (int.Parse(showMenuParam[0]) == i)
                            {
                                sb.AppendFormat("<ul style='display:block'>");
                            }
                            else
                            {
                                sb.AppendFormat("<ul>");
                            }
                        }
                        else
                        {
                            sb.AppendFormat("<ul>");
                        }
                        ////添加菜单项显示
                        for (int k = 0; k < subMenu.Length; k++)
                        {
                            node_Code = subMenu[k]["Node_Code"].ToString();
                            urlpage = subMenu[k]["Form_Name"].ToString();
                            title = subMenu[k]["Node_Name"].ToString();

                            if (showMenuParam.Length > 1)
                            {
                                if (int.Parse(showMenuParam[0]) == i && int.Parse(showMenuParam[1]) == k)
                                {
                                    sb.AppendFormat(" <li class='color0098c6'><a href=\"/{0}\">{1}</a></li>", urlpage, title);
                                }
                                else
                                {
                                    sb.AppendFormat(" <li><a href=\"/{0}\">{1}</a></li>", urlpage, title);
                                }
                            }
                            else
                            {
                                sb.AppendFormat(" <li><a href=\"/{0}\">{1}</a></li>", urlpage, title);
                            }
                        }

                        sb.AppendFormat("</ul></li>");
                    }
                }
            }

            return MvcHtmlString.Create(sb.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 登陆
        /// </summary>
        /// <returns>结果</returns>
        public ActionResult Index()
        {
            ClearCK1Cookie();

            if (SSOClientConfigHelper.SSOType == 0)
            {
                return this.SSOUrl();
            }
            else if (SSOClientConfigHelper.SSOType == 1)
            {
                ////有域名共享cookie方式,主要适用于大平台(自己域名),同时生成主域名凭证
                return this.SSOCookie();
            }
            else if (SSOClientConfigHelper.SSOType == 2)
            {
                ////兼容方式:先1后0(过渡期间使用)
                if (this.Request.Cookies["Ticket"] != null)
                {
                    // 新单点登陆
                    string uid = string.Empty;
                    try
                    {
                        DefaultClient ssoclient = new DefaultClient();
                        string msg = string.Empty;
                        uid = ssoclient.GetUserTicket();
                        if (!ssoclient.CheckLogin(out msg))
                        {
                            this.TempData["ResMsg"] = "获取账号信息失败";
                            return this.View("ErrorPage");
                        }
                        else
                        {
                            // 权限验证
                            uid = ssoclient.GetUserTicket();

                            TrackIdManager.GetInstance(uid);

                            if (!string.IsNullOrEmpty(uid))
                            {
                                UserLoginServiceHelper.UserLoginServiceHelper userHelper =
                                    new UserLoginServiceHelper.UserLoginServiceHelper();
                                MStaffInfo staffInfo = userHelper.GetStaffInfoModel(uid);
                                ////登录用户不为平台时限制ip
                                int staffType = staffInfo.StaffType;
                                if (staffType != 1)
                                {
                                    if (!userHelper.LimitIpLogin(staffInfo.Department_id, this.GetIpAddr()))
                                    {
                                        return this.Json("当前登录IP不在允许的登录IP范围内!", "text/html", JsonRequestBehavior.AllowGet);
                                    }
                                }

                                if (staffInfo.StaffType != 1)
                                {
                                    this.TempData["ResMsg"] = "当前账号无权限";
                                    return this.View("ErrorPage");
                                }

                                //// 登陆成功
                                FormsAuthentication.SetAuthCookie(staffInfo.Staff_id, false);

                                //// TODO 保存用户部门对象
                                this.Session["$sessionName$_UserInfo"] = staffInfo;

                                // 登录成功,创建本地票据
                                this.SetLocalTicket(staffInfo);

                                //// 页面跳转
                                if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request["RequestPage"]))
                                {
                                    return this.Redirect("~/" + HttpUtility.UrlDecode(System.Web.HttpContext.Current.Request["RequestPage"]));
                                }
                                else
                                {
                                    return this.Redirect("~/Home/Index");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // 单点登录失败吃掉异常
                        AppException appEx = new AppException(string.Empty, ex.Message, ex, null);
                        LogManager.Log.WriteException(appEx);
                    }
                }

                return this.SSOUrl();
            }

            return this.SSOUrl();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 老单点登录方式
        /// </summary>
        /// <returns>执行结果</returns>
        private ActionResult SSOUrl()
        {
            // 共享登陆
            if (this.Request["PartnerId"] != null)
            {
                try
                {
                    AuthenticateManager manager = new AuthenticateManager(
                        System.Web.HttpContext.Current.Request,
                        ConfigurationManager.AppSettings["SOOUrl"] + "/LoginInfoValidate.aspx");
                    //// 登陆成功
                    if (manager.Validate())
                    {
                        TrackIdManager.GetInstance(manager.AccountId);

                        //// 获取用户对象
                        UserLoginServiceHelper.UserLoginServiceHelper userHelper =
                            new UserLoginServiceHelper.UserLoginServiceHelper();

                        MStaffInfo staff = userHelper.GetStaffInfoModel(manager.AccountId);
                        ////登录用户不为平台时限制ip
                        int staffType = staff.StaffType;
                        if (staffType != 1)
                        {
                           if (!userHelper.LimitIpLogin(staff.Department_id, this.GetIpAddr()))
                           {
                               return this.Json("当前登录IP不在允许的登录IP范围内!", "text/html", JsonRequestBehavior.AllowGet);
                           }
                        }

                        ////  平台才能登陆 
                        if (staff.StaffType != 1)
                        {
                            this.TempData["ResMsg"] = "当前账号无权限";
                            return this.View("ErrorPage");
                        }
                        else
                        {
                            //// 登陆成功
                            FormsAuthentication.SetAuthCookie(staff.Staff_id, false);
                            this.SetLocalTicket(staff);

                            //// 保存会话Token
                            this.Session["Token"] = manager.Token;

                            //// TODO 保存用户对象
                            this.Session["$sessionName$_UserInfo"] = staff;

                            //// 页面跳转
                            if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request["RequestPage"]))
                            {
                                return this.Redirect("~/" + HttpUtility.UrlDecode(System.Web.HttpContext.Current.Request["RequestPage"]));
                            }
                            else
                            {
                                return this.Redirect("~/Home/Index");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // 单点登录失败吃掉异常
                    AppException appEx = new AppException(string.Empty, ex.Message, ex, null);
                    LogManager.Log.WriteException(appEx);
                }
            }
            else
            {
                this.ViewData["result"] = null;
            }

            return this.View();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 登陆按钮
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <param name="pwd">用户密码</param>
        /// <param name="validateCode">验证码</param>
        /// <returns>结果</returns>
        public JsonResult LoginIndex(string userID, string pwd, string validateCode)
        {
            string errMsg = string.Empty;
            string result = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(userID))
                {
                    result = "请输入用户名!";
                    return this.Json("请输入用户名!");
                }

                if (string.IsNullOrEmpty(pwd))
                {
                    result = "请输入密码!";
                    return this.Json("请输入密码!");
                }

                TrackIdManager.GetInstance(userID);

                if (string.IsNullOrEmpty(validateCode))
                {
                    ////TODO 提示输入验证码
                    result = "请输入验证码!";
                    return this.Json("请输入验证码!");
                }

                string sessionValidateCode = this.Session["validatecode"] == null ? string.Empty : this.Session["validatecode"].ToString();
                if (validateCode.Trim().ToLower() != sessionValidateCode.ToLower())
                {
                    ////TODO 提示验证码输入错误
                    result = "请输入验证码!";
                    return this.Json("验证码错误!");
                }

                ClearCK1Cookie();

                UserLoginServiceHelper.UserLoginServiceHelper userHelper = new UserLoginServiceHelper.UserLoginServiceHelper();

                string message = string.Empty;
                MLogin login = new MLogin();
                login.AccountId = userID;
                login.HostAddress = Request.UserHostAddress;

                MUserLoginInfo loginInfo = new MUserLoginInfo();
                loginInfo.Staff_Id = userID;
                loginInfo.Password = pwd;
                if (userHelper.CommonLogin(loginInfo, ref message, ref login))
                {
                    MStaffInfo staffInfo = userHelper.GetStaffInfoModel(userID);
                    ////登录用户不为平台时限制ip
                    int staffType = staffInfo.StaffType;
                    if (staffType != 1)
                    {
                       if (!userHelper.LimitIpLogin(staffInfo.Department_id, this.GetIpAddr()))
                       {
                           return this.Json("当前登录IP不在允许的登录IP范围内!", "text/html", JsonRequestBehavior.AllowGet);
                       }
                    }

                    //// 平台登陆 
                    if (staffInfo.StaffType != 1)
                    {
                        result = "当前账号无权限!";
                        return this.Json("当前账号无权限");
                    }

                    //// 登录成功,创建本地票据
                    this.SetLocalTicket(staffInfo);

                    //// TODO 保存用户对象
                    this.Session["$sessionName$_UserInfo"] = staffInfo;

                    FormsAuthentication.SetAuthCookie(userID, false);
                    result = "登陆成功";
                    return this.Json(result);
                }
                else
                {
                    result = "用户名或密码错误!";
                    return this.Json(result);
                }
            }
            catch (AppException app)
            {
                errMsg = app.Message;
                result = errMsg;
            }
            catch (Exception ex)
            {
                AppException app = new AppException(string.Empty, ex.Message, ex, null);
                LogManager.Log.WriteException(app);
                errMsg = app.Message;
                result = errMsg;
            }
            finally
            {
                string addr = string.Empty;
                try
                {
                    addr = IpLocator.GetIpLocation(System.Configuration.ConfigurationManager.AppSettings["IPFile"], this.GetIpAddr()).Country;
                }
                catch
                {
                }

                UiaccParam param = new UiaccParam();
                param.SysId = "您的网站名称";
                param.OperId = "登录";
                param.UiId = "点击登录按钮";
                param.UserIP = this.GetIpAddr();
                param.UserName = userID;
                param.KeyMessage = "您的网站名称用户登录" + "用户ID:" + userID + "登录结果:" + result + "登录域名:" + HttpContext.Request.Url.Authority + " 登录城市:" + addr;
                if (TrackIdManager.CurrentTrackID == null)
                {
                    TrackIdManager.GetInstance(param.UserName);
                }

                this.watch.Stop();
                param.TimeSpan = this.watch.Elapsed;
                Better.Infrastructures.Log.LogManager.Log.WriteUiAcc(param);
            }

            if (!string.IsNullOrEmpty(errMsg))
            {
                return this.Json("用户名或密码错误!");
            }

            return this.Json(string.Empty);
        }