/// <summary>
        /// 异常处理
        /// </summary>
        /// <param name="ex">异常</param>
        /// <returns>结果</returns>
        public static string ProcessException(Exception ex)
        {
            string msg = string.Empty;
            try
            {
                Type type = ex.GetType();
                if (type.Name == "Exception" ||
                    type.Name == "ApplicationException" ||
                    type.Name == "CommandAnalysisException" ||
                    type.Name == "ComunicateToEMException" ||
                    type.Name == "ObjectInitException")
                {
                    AppException app = new AppException(string.Empty, ex.Message, ex, null);
                    LogManager.Log.WriteException(app);
                    ////msg = ex.Message;
                    msg = string.Format("{0}:{1}<br />{2} <br />{3}", app.Code, app.CustomerMessage, app.ID.ToString(), TrackIdManager.CurrentTrackID.StrTrackID);
                    return msg;
                }

                if (type.Name == "AppException")
                {
                    AppException app = ex as AppException;
                    msg = string.Format("{0}:{1}<br />{2} <br />{3}", app.Code, app.CustomerMessage, app.ID.ToString(), TrackIdManager.CurrentTrackID.StrTrackID);
                    return msg;
                }

                if (type.Name.StartsWith("FaultException"))
                {
                    FaultException<TransferException> fe = ex as FaultException<TransferException>;
                    if (fe != null)
                    {
                        AppException app = new AppException(fe.Detail);
                        msg = string.Format("{0}:{1}<br />{2}<br />{3}", app.Code, app.CustomerMessage, app.ID.ToString(), TrackIdManager.CurrentTrackID.StrTrackID);
                        return msg;
                    }
                }

                AppException appEx = new AppException(string.Empty, ex.Message, ex, null);
                LogManager.Log.WriteException(appEx);
                if (TrackIdManager.CurrentTrackID == null)
                {
                    TrackIdManager.GetInstance("pt");
                }

                msg = string.Format("{0}:{1}<br />{2}<br />{3}", appEx.Code, appEx.CustomerMessage, appEx.ID.ToString(), TrackIdManager.CurrentTrackID.StrTrackID);
            }
            catch
            {
            }

            return msg;
        }
Exemple #2
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();
        }
Exemple #3
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();
        }
Exemple #4
0
 /// <summary>
 /// 设置单点登录本地Ticket
 /// </summary>
 /// <param name="staff">用户</param>
 private void SetLocalTicket(MStaffInfo staff)
 {
     try
     {
         if (SSOClientConfigHelper.SSOType == 1 || SSOClientConfigHelper.SSOType == 2)
         {
             DefaultClient client = new DefaultClient();
             client.SaveLocalTicket(staff.Staff_id);
         }
     }
     catch (Exception ex)
     {
         AppException appEx = new AppException(string.Empty, "认证中心故障:" + ex.Message, ex, null);
         LogManager.Log.WriteException(appEx);
     }
 }
Exemple #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);
        }