示例#1
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();
        }