Beispiel #1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //string customerCode = this.txtCustomerCode.Value.Trim();
            string account = this.txtUsername.Value.Trim();
            string pwd     = this.txtPassword.Value.Trim();

            //string authCode = txtValidateCode.Text.Trim();
            //将用户登录名密码提交到服务器检验

            //if (string.IsNullOrEmpty(customerCode) || customerCode == "公司编码")
            //{
            //    lblInfor.Text = "请输入公司编码!";
            //    txtCustomerCode.Focus();
            //    return;
            //}
            if (string.IsNullOrEmpty(account) || account == "用户名")
            {
                lblInfor.Text = "请输入用户名!";
                txtUsername.Focus();
                return;
            }

            if (string.IsNullOrEmpty(pwd))
            {
                lblInfor.Text = "请输入密码!";
                txtPassword.Focus();
                return;
            }


            Hashtable ht                 = new Hashtable();
            UserInfo  login_user         = null;
            var       loggingSessionInfo = GetLjLoggingSession();
            var       service            = new cUserService(loggingSessionInfo);

            try
            {
                int ret      = 0;
                var userList = service.SearchUserList(account, "", "", "", 1, 0);
                if (userList != null && userList.UserInfoList != null && userList.UserInfoList.Count > 0)
                {
                    login_user             = userList.UserInfoList[0];
                    login_user.customer_id = "43753855ae814fc093c281441972f8f1";
                    if (login_user.User_Status == "-1")
                    {
                        ret = -2;
                    }
                    else if (login_user.User_Password != EncryptManager.Hash(pwd, HashProviderType.MD5))
                    {
                        ret = -3;
                    }
                    else
                    {
                        ret = 1;
                    }
                }
                else
                {
                    ret = -1;
                }


                switch (ret)
                {
                case -1:
                    lblInfor.Text = "用户不存在";
                    return;

                case -2:
                    lblInfor.Text = "用户被停用";
                    return;

                case -3:
                    lblInfor.Text = "密码不正确";
                    return;

                case -4:
                    lblInfor.Text = "用户不在线";
                    return;

                case 1:
                    //用户名和密码验证通过
                    break;

                default:
                    lblInfor.Text = "用户名和密码不正确";
                    return;
                }
            }
            catch
            {
                lblInfor.Text = "用户名和密码不正确";
                return;
            }

            // chkRemember
            if (chkRemember.Checked)
            {
                Response.Cookies["cpos_sso_remember"].Value   = "1";
                Response.Cookies["cpos_sso_remember"].Expires = DateTime.MaxValue;

                Response.Cookies["cpos_sso_user"].Value   = account;
                Response.Cookies["cpos_sso_user"].Expires = DateTime.MaxValue;

                Response.Cookies["cpos_sso_pwd"].Value   = pwd;
                Response.Cookies["cpos_sso_pwd"].Expires = DateTime.MaxValue;
            }
            else
            {
                Response.Cookies["cpos_sso_remember"].Value = "";
                Response.Cookies["cpos_sso_user"].Value     = "";
                Response.Cookies["cpos_sso_pwd"].Value      = "";
            }

            //判断登录进来的用户是否存在,并且返回用户信息
            LoggingSessionInfo loggingSession = new LoggingSessionInfo();

            loggingSession.CurrentLoggingManager = new LoggingManager();
            loggingSession.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn;
            loggingSession.CurrentLoggingManager.Customer_Id       = loggingSessionInfo.CurrentUser.customer_id;

            loggingSession.CurrentUser = login_user;

            // 获取角色
            string applicationId = PageBase.JITPage.GetApplicationId();
            IList <UserRoleInfo> userRoleList = service.GetUserRoles(login_user.User_Id, applicationId);

            if (userRoleList != null && userRoleList.Count > 0)
            {
                loggingSession.CurrentUserRole          = new UserRoleInfo();
                loggingSession.CurrentUserRole.UserId   = login_user.User_Id;
                loggingSession.CurrentUserRole.UserName = login_user.User_Name;
                loggingSession.CurrentUserRole.RoleId   = userRoleList[0].RoleId;
                loggingSession.CurrentUserRole.RoleName = userRoleList[0].RoleName;

                loggingSession.ClientID = login_user.customer_id;
                loggingSession.CurrentLoggingManager.Customer_Id = login_user.customer_id;
                loggingSession.UserID = loggingSession.CurrentUser.User_Id;

                try
                {
                    loggingSession.CurrentUserRole.UnitId = service.GetDefaultUnitByUserIdAndRoleId(
                        loggingSession.CurrentUserRole.UserId, loggingSession.CurrentUserRole.RoleId);
                }
                catch (Exception ex)
                {
                    PageLog.Current.Write(ex);
                    Response.Write("找不到默认单位");
                    Response.End();
                }

                //try
                //{
                //    loggingSession.CurrentUserRole.UnitName = unitService.GetUnitById(
                //        loggingSessionInfo, loggingSession.CurrentUserRole.UnitId).ShortName;
                //}
                //catch (Exception ex)
                //{
                //    PageLog.Current.Write(ex);
                //    Response.Write("找不到单位");
                //    Response.End();
                //}
            }


            //this.Session["UserInfo"] = login_user;
            //this.Session["LoggingManager"] = myLoggingManager;
            //this.Session["loggingSessionInfo"] = loggingSession;


            //loggingSession.CurrentLoggingManager = myLoggingManager;
            new SessionManager().SetCurrentUserLoginInfo(loggingSession);

            //清空密码
            login_user.User_Password = null;

            string goURL = "~/Default.aspx";

            this.Response.Redirect(goURL);
        }