Ejemplo n.º 1
0
        protected void loginCon_Authenticate(object sender, AuthenticateEventArgs e)
        {
            #region dataset
            DataSet dataSet = new DataSet();
            DataRow userRow = null;

            DataColumn colName = new DataColumn("usrName", System.Type.GetType("System.String"));
            //DataColumn colAuth = new DataColumn("totleAuthority", System.Type.GetType("System.Int32"));
            DataColumn colPwd = new DataColumn("usrPassWord", System.Type.GetType("System.String"));
            //DataColumn colId = new DataColumn("usrId", System.Type.GetType("System.Int32"));
            //DataColumn colEnd = new DataColumn("endTime", System.Type.GetType("System.DateTime"));

            DataTable userTable = new DataTable("tbl_usr");

            //colName.DataType = System.Type.GetType("System.String");
            //colAuth.DataType = System.Type.GetType("System.Int32");
            //colPwd.DataType = System.Type.GetType("System.String");
            //colId.DataType = System.Type.GetType("System.Int32");

            //colName.ColumnName = "usrName";
            //colPwd.ColumnName = "usrPassWord";
            //colId.ColumnName = "usrId";
            //colAuth.ColumnName = "totleAuthority";

            userTable.Columns.Add(colName);
            //userTable.Columns.Add(colAuth);
            userTable.Columns.Add(colPwd);
            //userTable.Columns.Add(colId);
            //userTable.Columns.Add(colEnd);

            userRow                = userTable.NewRow();
            userRow["usrName"]     = loginCon.UserName.ToString().Trim();
            userRow["usrPassWord"] = loginCon.Password.ToString().Trim();
            //userRow["endTime"] = DateTime.Today;
            userTable.Rows.Add(userRow);

            dataSet.Tables.Add(userTable);
            #endregion


            //Xm_db xmDataCont = Xm_db.GetInstance();

            //var a =
            //    from b in xmDataCont.Tbl_usr
            //    where b.RealName.Equals("joker")
            //    select b;

            //int usrId = a.First().Tbl_usr_title.Where(p => p.UsrId == a.First().UsrId).Count(p => p.Tbl_title.EndTime > DateTime.Now);

            UserProcess myLogin = new UserProcess(dataSet);

            myLogin.DoLogin();
            int rowRtn = myLogin.IntRtn;

            if (0 != rowRtn)
            {
                using (DataTable dt =
                           myLogin.MyDst.Tables["tbl_usr"].DefaultView.ToTable())
                {
                    string         strUsrAuth = dt.Rows[0]["totleAuthority"].ToString();
                    AuthAttributes usrAuthAttr;
                    Enum.TryParse <AuthAttributes>(strUsrAuth, out usrAuthAttr);

                    //Session["totleAuthority"] =
                    //    dt.Rows[0]["totleAuthority"].ToString();
                    Session["totleAuthority"] =
                        usrAuthAttr;
                    Session["usrId"] =
                        dt.Rows[0]["usrId"].ToString();

                    string strRealName =
                        dt.Rows[0]["realName"].ToString();
                    FormsAuthentication.SetAuthCookie(strRealName, false);

                    string backUrl     = Session["backUrl"] as string;
                    string continueUrl = "~/Main/DefaultMainSite.aspx";//Request.QueryString["ReturnUrl"];
                    if (!String.IsNullOrEmpty(backUrl))
                    {
                        continueUrl = backUrl;
                    }
                    else
                    {
                    }
                    Response.Redirect(continueUrl);
                    //aspxName = myLogin.StrRtn + "Main.aspx";
                    //Server.Transfer(aspxName);
                }
            }
            else
            {
            }
        }