Ejemplo n.º 1
0
        override protected void OnInit(EventArgs e)
        {
            Page.Response.Expires = -1;
            base.OnInit(e);
            this.InitEventHandler();
            //调试状态下用admin
            if ((Session["User"] == null) && (Request["DebugUser"] + "" != ""))
            {
                Session["User"] = new User(Request["DebugUser"] + "");
                this.user       = (User)Session["User"];

                /********************** 在线用户统计 ***************************/
                Application.Lock();
                Hashtable UserTable = (Hashtable)Application["UserTable"];
                if (UserTable != null)
                {
                    if (!UserTable.Contains(user.UserCode + "," + Session.SessionID))
                    {
                        UserTable.Add(user.UserCode + "," + Session.SessionID, user.UserName);
                        Application["UserTable"] = UserTable;
                    }

                    //单一用户登录控制
                    if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
                    {
                        Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];
                        KillUser(user, UserTable, KilledUserTable, Session);
                    }
                }

                Application.UnLock();
                /***************************************************************/
            }

            if ((Session["User"] == null) && (ConfigurationSettings.AppSettings["IsDebug"] == "1") && (ConfigurationSettings.AppSettings["DebugUser"] != ""))
            {
                Session["User"] = new User(ConfigurationSettings.AppSettings["DebugUser"]);
                this.user       = (User)Session["User"];

                /********************** 在线用户统计 ***************************/
                Application.Lock();
                Hashtable UserTable = (Hashtable)Application["UserTable"];
                if (UserTable != null)
                {
                    if (!UserTable.Contains(user.UserCode + "," + Session.SessionID))
                    {
                        UserTable.Add(user.UserCode + "," + Session.SessionID, user.UserName);
                        Application["UserTable"] = UserTable;
                    }

                    //单一用户登录控制
                    if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
                    {
                        Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];
                        KillUser(user, UserTable, KilledUserTable, Session);
                    }
                }

                Application.UnLock();
                /***************************************************************/
            }

            if (Session["User"] != null)
            {
                this.user = (User)Session["User"];

                //超过限制时间时需要重新登录
                if (!Page.IsPostBack)                 //页面回发时不判断超时
                {
                    if (!user.IsWindowsAuthenticated) //windows用户自动登录时不判断超时
                    {
                        decimal LoginTimeOut = BLL.ConvertRule.ToDecimal(Application["LoginTimeOut"]);
                        if (LoginTimeOut > 0)
                        {
                            //最后操作时间
                            if (Session["LastOperTime"] != null)
                            {
                                TimeSpan ts = DateTime.Now.Subtract((DateTime)Session["LastOperTime"]);
                                if (ts.Minutes > LoginTimeOut) //超时
                                {
                                    Session["User"] = null;
                                }
                            }
                        }
                    }
                }
            }

            //禁止匿名登录时,取windows用户自动登录 2007.2.24
            if ((Session["User"] == null) && Page.User.Identity.IsAuthenticated)
            {
                string UserID = Page.User.Identity.Name;
                if (UserID.IndexOf("\\") > 0)
                {
                    int num1 = UserID.IndexOf(@"\") + 1;
                    UserID = UserID.Substring(num1, UserID.Length - num1);
                }
                this.user = new User();
                if (user.LoadUserByUserID(UserID))
                {
                    user.IsWindowsAuthenticated = true;
                    Session["User"]             = user;

                    /********************** 在线用户统计 ***************************/
                    Application.Lock();
                    Hashtable UserTable = (Hashtable)Application["UserTable"];
                    if (!UserTable.Contains(user.UserCode + "," + Session.SessionID))
                    {
                        UserTable.Add(user.UserCode + "," + Session.SessionID, user.UserName);
                        Application["UserTable"] = UserTable;
                    }

                    //单一用户登录控制
                    if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
                    {
                        Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];
                        PageBase.KillUser(user, UserTable, KilledUserTable, Session);
                    }

                    Application.UnLock();
                    /***************************************************************/
                }
            }

            if (Session["User"] == null) //需要重新登陆
            {
                //记录需要重新登录事件 by Simon
                LogHelper.Info("重新登录 IP:" + Request.UserHostAddress + " URL: " + Request.Url);

                //登录页面
                string url = ResolveClientUrl("~/Default.aspx");
                Response.Write(Rms.Web.JavaScript.ScriptStart);
                Response.Write(String.Format(@"  if ( window.parent == null ) window.open('{0}','a'); else  window.parent.open('{0}','a');  ", url));
                //				Response.Write ( @"  if ( window.parent == null ) window.open('.\\Default.aspx'); else  window.parent.open('.\\Default.aspx');  " );
                //				Response.Write( Rms.Web.JavaScript.WinOpenMax(false,@"\Default.aspx",""));
                //				Response.Write( Rms.Web.JavaScript.WinClose(false));
                Response.Write(@"  if ( window.parent == null ) { window.opener=null;  window.close() ; } else  { window.parent.opener = null; window.parent.close(); } ");
                Response.Write(Rms.Web.JavaScript.ScriptEnd);
                Response.End();
            }

            //单一用户登录控制
            if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
            {
                Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];

                if (KilledUserTable != null)
                {
                    if (KilledUserTable.Contains(user.UserCode + "," + Session.SessionID))
                    {
                        //记录被弹出事件
                        LogHelper.Info("用户被弹出 IP:" + Request.UserHostAddress + " URL: " + Request.Url);

                        Session.Abandon();

                        Response.Write(Rms.Web.JavaScript.Alert(true, "您被弹出"));

                        //登录页面
                        string url = ResolveClientUrl("~/Default.aspx");
                        Response.Write(Rms.Web.JavaScript.ScriptStart);
                        Response.Write(String.Format(@"  if ( window.parent == null ) window.open('{0}','a'); else  window.parent.open('{0}','a');  ", url));
                        Response.Write(@"  if ( window.parent == null ) { window.opener=null;  window.close() ; } else  { window.parent.opener = null; window.parent.close(); } ");
                        Response.Write(Rms.Web.JavaScript.ScriptEnd);

                        //清弹出用户列表
                        Application.Lock();
                        KilledUserTable.Remove(user.UserCode + "," + Session.SessionID);
                        Application["KilledUserTable"] = KilledUserTable;
                        Application.UnLock();

                        Response.End();
                    }
                }
            }


//			if (Session["ProjectCode"] != null)
//			{
//				ProjectCode = Session["ProjectCode"].ToString();
//			}

            if (Session["Project"] != null)
            {
                project = (ProjectInfo)Session["Project"];
            }

            //记录最后操作时间
            Session["LastOperTime"] = DateTime.Now;
        }
Ejemplo n.º 2
0
        private void Login(string userID, string pwd, bool IsNeedPwd)
        {
            try
            {
                UserStrategyBuilder sb = new UserStrategyBuilder(); //获取SQL查询语句;
                if (System.Configuration.ConfigurationSettings.AppSettings["UserNameLogin"] == "1")
                {
                    sb.AddStrategy(new Strategy(UserStrategyName.UserIdorUserName, userID));  //将用户ID值加入到Strategy;
                    if (IsNeedPwd)
                    {
                        sb.AddStrategy(new Strategy(UserStrategyName.PassWord, pwd));
                    }
                }
                else
                {
                    sb.AddStrategy(new Strategy(UserStrategyName.UserID, userID));
                }
                string sql = sb.BuildMainQueryString();

                Rms.ORMap.QueryAgent qa     = new QueryAgent();                     //打开数据库;
                EntityData           entity = qa.FillEntityData("SystemUser", sql); //读取数据数据;
                qa.Dispose();
                string workNO = "";

                bool OK = false;
                if (!entity.HasRecord())
                {
                    this.lblMessage.Text = "用户名或密码错误";
                }
                else
                {
                    string RealPwd = entity.GetString("Password");
                    if (pwd != RealPwd && IsNeedPwd)
                    {
                        this.lblMessage.Text = "用户名或密码错误";
                    }
                    else
                    {
                        int status = entity.GetInt("Status");
                        // 0-正常,1 禁用
                        if (status == 1)
                        {
                            this.lblMessage.Text = "该用户已被禁用";
                        }
                        else
                        {
                            string userCode = entity.GetString("UserCode");
                            User   user     = new User(userCode);
                            //user.ResetUser("P1010");
                            Session["User"] = user;
                            workNO          = user.WorkNO;

                            //是否缺省显示最后一次访问的项目
                            string UseLastProject = System.Configuration.ConfigurationSettings.AppSettings["UseLastProject"];
                            if (UseLastProject == "1")
                            {
                                // 取用户最后使用的项目,如果没有取用户能进入的项目, 和用户权限相结合
                                string projectCode = entity.GetString("LastProjectCode");

                                if (projectCode == "")
                                {
                                    // 这里要修改, 取用户能进入的项目
                                    EntityData projects = DAL.EntityDAO.ProjectDAO.GetAllProject();
                                    if (projects.HasRecord())
                                    {
                                        projectCode = projects.GetString("ProjectCode");
                                    }
                                    projects.Dispose();
                                }

                                Session["ProjectCode"] = projectCode;
                                if (projectCode != "")
                                {
                                    ((ProjectInfo)Session["project"]).Reset(projectCode);
                                }
                            }

                            OK = true;

                            /********************** 在线用户统计 ***************************/
                            Application.Lock();
                            Hashtable UserTable = (Hashtable)Application["UserTable"];
                            if (!UserTable.Contains(user.UserCode + "," + Session.SessionID))
                            {
                                UserTable.Add(user.UserCode + "," + Session.SessionID, user.UserName);
                                Application["UserTable"] = UserTable;
                            }

                            //单一用户登录控制
                            if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
                            {
                                Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];
                                PageBase.KillUser(user, UserTable, KilledUserTable, Session);
                            }

                            Application.UnLock();
                            /***************************************************************/
                        }
                    }
                }
                entity.Dispose();

                if (OK)
                {
                    //记录最后操作时间
                    Session["LastOperTime"] = DateTime.Now;

                    string strOaPath = System.Configuration.ConfigurationSettings.AppSettings["OAUrl"];
                    Response.Write(@"<Script language=""javascript"" src=""./Rms.js""></Script>");
                    Response.Write(Rms.Web.JavaScript.ScriptStart);
                    Response.Write("window.opener=null;");
                    string usercode = ((User)Session["User"]).UserCode;
                    Response.Write(@" var win = OpenFullWindow('frame.htm','房产项目管理系统" + (usercode == "0"?(DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString()):usercode) + "'); ");
                    Response.Write(@" if ( win != this ) { win.opener = null;window.open('', '_parent', ''); window.close(); }");
                    Response.Write(Rms.Web.JavaScript.ScriptEnd);
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteLog(this.ToString(), ex, "用户登录失败");
                Response.Write(Rms.Web.JavaScript.Alert(true, "用户登录失败:" + ex.Message));
            }
        }
Ejemplo n.º 3
0
        private bool Login(string userID, string pwd, bool IsNeedPwd)
        {
            try
            {
                bool OK = false;
                UserStrategyBuilder sb = new UserStrategyBuilder();
                sb.AddStrategy(new Strategy(UserStrategyName.UserID, userID));
                string sql = sb.BuildMainQueryString();

                Rms.ORMap.QueryAgent qa     = new QueryAgent();
                EntityData           entity = qa.FillEntityData("SystemUser", sql);
                qa.Dispose();
                string workNO = "";


                if (!entity.HasRecord())
                {
                }
                else
                {
                    string RealPwd = entity.GetString("Password");
                    if (RealPwd != pwd)
                    {
                        OK = false;
                    }
                    else
                    {
                        int status = entity.GetInt("Status");
                        // 0-正常,1 禁用
                        if (status == 0)
                        {
                            string userCode = entity.GetString("UserCode");
                            User   user     = new User(userCode);
                            //						user.ResetUser("P1010");
                            Session["User"]       = user;
                            ViewState["UserName"] = userID;
                            ViewState["Password"] = pwd;
                            workNO = user.WorkNO;
                            OK     = true;

                            /********************** 在线用户统计 ***************************/
                            Application.Lock();
                            Hashtable UserTable = (Hashtable)Application["UserTable"];
                            if (!UserTable.Contains(user.UserCode + "," + Session.SessionID))
                            {
                                UserTable.Add(user.UserCode + "," + Session.SessionID, user.UserName);
                                Application["UserTable"] = UserTable;
                            }

                            //单一用户登录控制
                            if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
                            {
                                Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];
                                PageBase.KillUser(user, UserTable, KilledUserTable, Session);
                            }

                            Application.UnLock();
                            /***************************************************************/
                        }
                    }
                }
                entity.Dispose();

                if (OK)
                {
                    //记录最后操作时间
                    Session["LastOperTime"] = DateTime.Now;
                }
                return(OK);
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteLog(this.ToString(), ex, "用户登录失败");
                Response.Write(Rms.Web.JavaScript.Alert(true, "用户登录失败:" + ex.Message));
                return(false);
            }
        }