protected void ImageButtonLogin_Click(object sender, EventArgs e)
        {
            #region 验证服务器端狗信息
            ET99FullClass et99   = new ET99FullClass();
            Random        random = new Random((int)(DateTime.Now.Ticks >> 32));
            string        strServerRandomData   = string.Empty;
            string        strServerRandomResult = string.Empty;
            string        strServerPid          = string.Empty;
            string        strServerUserpin      = string.Empty;
            //string strServerSn = string.Empty;
            string strServerKey = string.Empty;

            for (int i = 0; i < 20; i++)
            {
                strServerRandomData += random.Next(9).ToString();
            }

            try
            {
                strServerPid = ConfigurationManager.AppSettings["PID"];
                et99.FindToken(strServerPid);
            }
            catch
            {
                SessionSet.PageMessage = "服务器端未检测到加密锁!";
                return;
            }
            try
            {
                et99.OpenToken(strServerPid, 1);
            }
            catch
            {
                SessionSet.PageMessage = "服务器端打开加密锁失败!";
                et99.CloseToken();
                return;
            }
            try
            {
                strServerUserpin = ConfigurationManager.AppSettings["USERPIN"];
                et99.VerifyPIN(0, strServerUserpin);
            }
            catch
            {
                SessionSet.PageMessage = "服务器端加密锁USERPIN不正确!";
                et99.CloseToken();
                return;
            }

            try
            {
                strServerKey          = ConfigurationManager.AppSettings["KEY1"];
                strServerRandomResult = et99.MD5HMAC(1, strServerRandomData, 20).ToString();
                if (strServerRandomResult != et99.Soft_MD5HMAC(1, strServerRandomData, strServerKey).ToString())
                {
                    SessionSet.PageMessage = "服务器端加密锁密钥不正确!";
                    return;
                }
            }
            catch
            {
                SessionSet.PageMessage = "服务器端验证加密锁密钥出错!";
                return;
            }
            #endregion

            if (ddlOrg.SelectedValue == "0")
            {
                SessionSet.PageMessage = "请选择单位!";
                return;
            }

            LoginUserBLL loginUserBLL = new LoginUserBLL();
            LoginUser    loginUser;

            if (PrjPub.IsServerCenter)
            {
                loginUser = loginUserBLL.GetLoginUserByOrgID(Convert.ToInt32(ddlOrg.SelectedValue), txtUserName.Text, txtPassword.Text, 0);
            }
            else
            {
                loginUser = loginUserBLL.GetLoginUserByOrgID(Convert.ToInt32(ddlOrg.SelectedValue), txtUserName.Text, txtPassword.Text, 1);
            }

            if (loginUser == null)
            {
                SessionSet.PageMessage = "您输入的用户名或密码不正确!";
                return;
            }

            string strUser     = string.Empty;
            string strCacheKey = loginUser.EmployeeID.ToString();

            strUser = Convert.ToString(Cache[strCacheKey]);

            SystemUserLoginBLL      objloginBll = new SystemUserLoginBLL();
            IList <SystemUserLogin> objList     = objloginBll.GetSystemUserLogin(loginUser.EmployeeID);

            if (strUser == string.Empty || objList.Count == 0)
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);

                Cache.Insert(strCacheKey, strCacheKey, null, DateTime.MaxValue, SessTimeOut, CacheItemPriority.NotRemovable, null);
                Session["User"] = strCacheKey;

                if (objList.Count == 0)
                {
                    SystemUserLogin objLogin = new SystemUserLogin();
                    objLogin.EmployeeID = loginUser.EmployeeID;
                    objLogin.IPAddress  = Pub.GetRealIP();
                    objloginBll.DeleteSystemUserLogin(loginUser.EmployeeID);
                    objloginBll.AddSystemUserLogin(objLogin);
                }
            }
            else
            {
                SessionSet.PageMessage = "该用户已经登录,不能重复登录!";
                return;
            }

            PrjPub.CurrentLoginUser     = loginUser;
            PrjPub.CurrentStudent       = loginUser;
            PrjPub.WelcomeInfo          = loginUser.OrgName + ":" + loginUser.EmployeeName + ",您好!";
            PrjPub.StudentID            = loginUser.EmployeeID.ToString();
            hfEmployeeID.Value          = loginUser.EmployeeID.ToString();
            Session["StudentOrdID"]     = loginUser.OrgID;
            SessionSet.UserID           = loginUser.UserID;
            SessionSet.EmployeeID       = loginUser.EmployeeID;
            SessionSet.EmployeeName     = loginUser.EmployeeName;
            SessionSet.OrganizationID   = loginUser.OrgID;
            SessionSet.OrganizationName = loginUser.OrgName;
            SessionSet.StationOrgID     = loginUser.StationOrgID;

            EmployeeBLL     objEmployeeBll = new EmployeeBLL();
            OrganizationBLL objOrgBll      = new OrganizationBLL();
            //控件显示
            lblUserName.Text = "姓&nbsp;&nbsp;&nbsp;&nbsp;名:";
            lblOrgName.Text  = objOrgBll.GetOrganization(loginUser.StationOrgID).ShortName;

            lblPassword.Text     = "工资编号:";
            lblOrg.Text          = objEmployeeBll.GetEmployee(loginUser.EmployeeID).WorkNo;
            lblEmployeeName.Text = loginUser.EmployeeName;

            lbl.Visible     = true;
            lblPost.Visible = true;
            lblPost.Text    = loginUser.PostName;

            if (Request.QueryString.Get("Type") == "middle")
            {
                ddlOrg.Visible           = false;
                lblOrgName.Visible       = true;
                txtUserName.Visible      = false;
                txtPassword.Visible      = false;
                ImageButtonLogin.Visible = false;
                btnExit.Visible          = true;
                lblOrg.Visible           = true;
                lblEmployeeName.Visible  = true;
                btnModifyPsw.Visible     = true;
                btnExam.Visible          = true;

                //ClientScript.RegisterStartupScript(GetType(),
                //        "jsSelectFirstNode",
                //        @"ShowExamList();",
                //        true);

                //ClientScript.RegisterStartupScript(GetType(), "import", "inputCallback.callback('middle');", true);
            }
            else if (Request.QueryString.Get("Type") == "right")
            {
                ddlOrg.Visible           = false;
                lblOrgName.Visible       = true;
                txtUserName.Visible      = false;
                txtPassword.Visible      = false;
                ImageButtonLogin.Visible = false;
                btnExit.Visible          = true;
                lblOrg.Visible           = true;
                lblEmployeeName.Visible  = true;
                btnModifyPsw.Visible     = true;
                btnResult.Visible        = true;

                //ClientScript.RegisterStartupScript(GetType(),
                //    "jsSelectFirstNode",
                //    @"ShowResultList();",
                //    true);

                //ClientScript.RegisterStartupScript(GetType(), "import", "inputCallback.callback('right');", true);
            }
            else if (Request.QueryString.Get("Type") == "left")
            {
                //将此人的登录次数+1
                EmployeeBLL objEmpBll = new EmployeeBLL();
                Employee    employee  = objEmpBll.GetEmployee(loginUser.EmployeeID);

                employee.LoginCount = employee.LoginCount + 1;
                if (PrjPub.IsServerCenter)
                {
                    objEmpBll.UpdateEmployee(employee);
                }
                else
                {
                    objEmpBll.UpdateEmployeeInStation(employee);
                }

                ddlOrg.Visible           = false;
                lblOrgName.Visible       = true;
                txtUserName.Visible      = false;
                txtPassword.Visible      = false;
                ImageButtonLogin.Visible = false;
                btnExit.Visible          = true;
                lblOrg.Visible           = true;
                lblEmployeeName.Visible  = true;
                btnModifyPsw.Visible     = true;
                btnExam.Visible          = false;
                btnStudy.Visible         = true;
            }
        }
Exemple #2
0
        protected void ImageButtonLogin_Click(object sender, ImageClickEventArgs e)
        {
            #region 验证服务器端狗信息

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["PID"]))
            {
                ET99FullClass et99 = new ET99FullClass();

                Random random = new Random((int)(DateTime.Now.Ticks >> 32));
                string strServerRandomData   = string.Empty;
                string strServerRandomResult = string.Empty;
                string strServerPid          = string.Empty;
                string strServerUserpin      = string.Empty;
                //string strServerSn = string.Empty;
                string strServerKey = string.Empty;

                for (int i = 0; i < 20; i++)
                {
                    strServerRandomData += random.Next(9).ToString();
                }

                try
                {
                    strServerPid = ConfigurationManager.AppSettings["PID"];
                    et99.FindToken(strServerPid);
                }
                catch
                {
                    SessionSet.PageMessage = "服务器端未检测到加密锁!";
                    return;
                }
                try
                {
                    et99.OpenToken(strServerPid, 1);
                }
                catch
                {
                    SessionSet.PageMessage = "服务器端打开加密锁失败!";
                    et99.CloseToken();
                    return;
                }
                try
                {
                    strServerUserpin = ConfigurationManager.AppSettings["USERPIN"];
                    et99.VerifyPIN(0, strServerUserpin);
                }
                catch
                {
                    SessionSet.PageMessage = "服务器端加密锁USERPIN不正确!";
                    et99.CloseToken();
                    return;
                }
                //try
                //{
                //    strServerSn = ConfigurationManager.AppSettings["SN"];
                //    if (et99.GetSN().ToString() != strServerSn)
                //    {
                //        SessionSet.PageMessage = "服务器端加密锁SN不正确!";
                //        return;
                //    }
                //}
                //catch
                //{
                //    SessionSet.PageMessage = "服务器端获取加密锁SN出错!";
                //}
                try
                {
                    strServerKey          = ConfigurationManager.AppSettings["KEY1"];
                    strServerRandomResult = et99.MD5HMAC(1, strServerRandomData, 20).ToString();
                    if (strServerRandomResult != et99.Soft_MD5HMAC(1, strServerRandomData, strServerKey).ToString())
                    {
                        SessionSet.PageMessage = "服务器端加密锁密钥不正确!";
                        return;
                    }
                }
                catch
                {
                    SessionSet.PageMessage = "服务器端验证加密锁密钥出错!";
                    return;
                }
            }

            #endregion

            LoginUserBLL loginUserBLL = new LoginUserBLL();
            LoginUser    loginUser;


            if (PrjPub.IsServerCenter)
            {
                loginUser = loginUserBLL.GetLoginUser(txtUserName.Text, txtPassword.Text, 0);
            }
            else
            {
                loginUser = loginUserBLL.GetLoginUser(txtUserName.Text, txtPassword.Text, 1);
            }


            if (loginUser == null)
            {
                SessionSet.PageMessage = "您输入的用户名或密码不正确!";
                return;
            }

            if (loginUser.RoleID == 0)
            {
                PrjPub.CurrentStudent   = loginUser;
                PrjPub.WelcomeInfo      = loginUser.OrgName + ":" + loginUser.EmployeeName + ",您好!";
                PrjPub.StudentID        = loginUser.EmployeeID.ToString();
                Session["StudentOrdID"] = loginUser.OrgID;
                Response.Redirect("Online/AccountManage.aspx");
            }

            PrjPub.CurrentLoginUser     = loginUser;
            PrjPub.WelcomeInfo          = loginUser.OrgName + ":" + loginUser.EmployeeName + ",您好!";
            SessionSet.UserID           = loginUser.UserID;
            SessionSet.EmployeeID       = loginUser.EmployeeID;
            SessionSet.EmployeeName     = loginUser.EmployeeName;
            SessionSet.OrganizationID   = loginUser.OrgID;
            SessionSet.OrganizationName = loginUser.OrgName;
            SessionSet.StationOrgID     = loginUser.StationOrgID;


            //if (!PrjPub.IsWuhan() && loginUser.EmployeeID != 1 && loginUser.EmployeeID != 2 && !(loginUser.RoleID==2 && !PrjPub.IsServerCenter))
            //{
            //    string strUser = string.Empty;
            //    string strCacheKey = loginUser.EmployeeID.ToString();

            //    strUser = Convert.ToString(Cache[strCacheKey]);

            //    SystemUserLoginBLL objloginBll = new SystemUserLoginBLL();
            //    IList<SystemUserLogin> objList = objloginBll.GetSystemUserLogin(loginUser.EmployeeID);

            //    if (strUser == string.Empty || objList.Count == 0)
            //    {
            //        TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);

            //        Cache.Insert(strCacheKey, strCacheKey, null, DateTime.MaxValue, SessTimeOut, CacheItemPriority.NotRemovable, null);
            //        Session["User"] = strCacheKey;

            //        if(objList.Count == 0)
            //        {
            //            SystemUserLogin objLogin = new SystemUserLogin();
            //            objLogin.EmployeeID = loginUser.EmployeeID;
            //            objLogin.IPAddress = Pub.GetRealIP();
            //            objloginBll.DeleteSystemUserLogin(loginUser.EmployeeID);
            //            objloginBll.AddSystemUserLogin(objLogin);
            //        }
            //    }
            //    else
            //    {
            //        SessionSet.PageMessage = "该用户已经登录,不能重复登录!";
            //        return;
            //    }
            //}

            //判断用户数

            //ApplicationSet.UserCount ++;
            //if (ApplicationSet.UserCount > ApplicationSet.AllowUserCount)
            //{
            //    SessionSet.PageMessage = "系统已达最大用户数,请稍候登录!";
            //    ApplicationSet.UserCount --;
            //    return;
            //}

            ////控件显示
            //lblUserName.Text = "使用部门:";
            //lblPassword.Text = "登录用户:";
            //lblDepartment.Text = loginUser.OrgName;
            //lblEmployee.Text = loginUser.EmployeeName;
            //lblUserCount.Text = "用户许可数:&nbsp;&nbsp;" + ApplicationSet.AllowUserCount.ToString();

            //txtUserName.Visible = false;
            //txtPassword.Visible = false;
            //ImageButtonLogin.Visible = false;
            //lblDepartment.Visible = true;
            //lblEmployee.Visible = true;
            //lblUserCount.Visible = true;

            ////将登录用户添加到在线用户数组
            //ApplicationSet.UserOnline.Add(loginUser.UserID);

            ////登录成功标志
            //SessionSet.Login = true;

            //设置Form许可
            FormsAuthentication.SetAuthCookie(loginUser.UserID, false);

            //HttpBrowserCapabilities brObject = Request.Browser;
            //SessionSet.PageMessage = brObject.Type;

            if (string.IsNullOrEmpty(Request.QueryString.Get("type")))
            {
                loginUser.IsDangan = false;
                Response.Redirect("Main/Admin_Index.aspx");
            }
            else
            {
                loginUser.IsDangan = true;
                Response.Redirect("Main/Admin_Index_Dangan.aspx");
            }
        }