protected void Page_Init(object sender, EventArgs e)
    {
        if (Request.Cookies["Cookies"] == null)
        {
            Response.Write("<script language='javascript'>alert('您没有权限进入本页或当前登录用户已过期!\\n请重新登录或与管理员联系!');parent.location='../login.aspx';</script>");
            return;
        }

        string strPageName = Request.Url.AbsolutePath;

        strPageName = strPageName.Substring(strPageName.LastIndexOf("/") + 1);

        string strSql = "select count(*) from t_R_Role,t_R_RoleMenu,t_R_Menu " +
                        "where t_R_Role.RoleID='" + Request.Cookies["Cookies"].Values["u_role"] +
                        "' and t_R_Menu.RelativeFile like '%" + strPageName +
                        "%' and t_R_Role.RoleID=t_R_RoleMenu.RoleID and t_R_RoleMenu.checked='1' and t_R_RoleMenu.MenuID=t_R_Menu.ID";
        MyDataOp mdo = new MyDataOp(strSql);
        DataSet  ds  = mdo.CreateDataSet();

        int intRow = Convert.ToUInt16(ds.Tables[0].Rows[0][0].ToString());

        if (intRow == 0)
        {
            Response.Write("<script language='javascript'>alert('您没有权限进入本页!\\n请重新登录或与管理员联系!');history.back();</script>");
        }
    }
示例#2
0
    protected void btn_Login_Click(object sender, ImageClickEventArgs e)
    {
        if (txt_UserName.Text.Trim() != "user")
        {
            if (SSOHelper.CheckOnline(txt_UserName.Text.Trim()))
            {
                string   strSql = "select DepartID,UserID,t_R_UserInfo.RoleID,PWDModifyTime,Name,LevelID,ReadRight,WriteRight,RefreshRight,FileRight,id,ManageRight,dataflag from t_R_UserInfo inner join t_R_Role on t_R_Role.RoleID=t_R_UserInfo.RoleID where  t_R_UserInfo.flag=0 and UserID='" + txt_UserName.Text.Trim() + "' and PWD='" + txt_Pwd.Text.Trim() + "'";
                MyDataOp mdo    = new MyDataOp(strSql);
                DataSet  ds     = mdo.CreateDataSet();

                if (ds.Tables[0].Rows.Count == 0)
                {
                    Response.Write("<script language='javascript'>alert('帐户或密码输入错误!请重新输入!');</script>");
                }
                else
                {
                    HttpCookie Cookie = new HttpCookie("Cookies");

                    DateTime dt = DateTime.Now;
                    TimeSpan ts = new TimeSpan(0, 10, 0, 0); //有效期10小时;
                    Cookie.Expires = dt.Add(ts);
                    Cookie.Values.Add("uid", ds.Tables[0].Rows[0]["id"].ToString());
                    Cookie.Values.Add("u_id", ds.Tables[0].Rows[0]["UserID"].ToString());
                    Cookie.Values.Add("u_role", ds.Tables[0].Rows[0]["RoleID"].ToString());
                    Cookie.Values.Add("u_flag", ds.Tables[0].Rows[0]["dataflag"].ToString());
                    Cookie.Values.Add("u_pswdtime", ds.Tables[0].Rows[0]["PWDModifyTime"].ToString());
                    Cookie.Values.Add("Name", HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Name"].ToString()));
                    //Cookie.Values.Add("u_Name",ds.Tables[0].Rows[0]["Name"].ToString());//用户名
                    // Cookie.Values.Add("RealName", HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["RealName"].ToString()));

                    Cookie.Values.Add("u_level", ds.Tables[0].Rows[0]["LevelID"].ToString());
                    Cookie.Values.Add("u_purview", ds.Tables[0].Rows[0]["ReadRight"].ToString() + //读权限
                                      ds.Tables[0].Rows[0]["WriteRight"].ToString() +             //写权限
                                      ds.Tables[0].Rows[0]["ManageRight"].ToString() +
                                      ds.Tables[0].Rows[0]["FileRight"].ToString());              //刷新权限;
                    Cookie.Values.Add("departid", ds.Tables[0].Rows[0]["DepartID"].ToString());
                    Response.AppendCookie(Cookie);
                    SSOHelper sso = new SSOHelper();
                    sso.LoginRegister(txt_UserName.Text.Trim());

                    Response.Redirect("~/main.htm");
                }
            }
            else
            {
                Response.Write("<script language='javascript'>alert('您的帐户已在别处登陆!');</script>");
            }
        }
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        txt_UserName.Focus();

        if (!Page.IsPostBack)
        {
            if (Request.QueryString["function"] != null)
            {
                string code        = "";
                string codecompare = System.Configuration.ConfigurationManager.AppSettings["LoginCode"].ToString();
                try
                {
                    code = DESEncrypt.Decrypt(Request.QueryString["function"]).ToString();
                }
                catch
                {
                    string encode = DESEncrypt.Encrypt(codecompare);
                }
                if (code == codecompare)
                {
                    string strSql = "select DepartID,UserID,t_R_UserInfo.RoleID,PWDModifyTime,Name,LevelID,ReadRight,WriteRight,RefreshRight,FileRight,id from t_R_UserInfo inner join t_R_Role on t_R_Role.RoleID=t_R_UserInfo.RoleID where UserID='user' and PWD='user'";

                    //
                    // string strSql = "select id,UserID,t_R_UserInfo.RoleID,Name,RealName,PWDModifyTime,LevelID,ReadRight,WriteRight,RefreshRight,id from t_R_UserInfo inner join t_R_Role on t_R_Role.RoleID=t_R_UserInfo.RoleID where UserID='user' and PWD='user'";
                    MyDataOp mdo = new MyDataOp(strSql);
                    DataSet  ds  = mdo.CreateDataSet();

                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        Response.Write("<script language='javascript'>alert('帐户或密码输入错误!请重新输入!');</script>");
                    }
                    else
                    {
                        HttpCookie Cookie = new HttpCookie("Cookies");

                        DateTime dt = DateTime.Now;
                        TimeSpan ts = new TimeSpan(0, 10, 0, 0); //有效期10小时;
                        Cookie.Expires = dt.Add(ts);
                        Cookie.Values.Add("uid", ds.Tables[0].Rows[0]["id"].ToString());
                        Cookie.Values.Add("u_id", ds.Tables[0].Rows[0]["UserID"].ToString());
                        Cookie.Values.Add("Name", HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Name"].ToString()));
                        // Cookie.Values.Add("RealName", HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["RealName"].ToString()));
                        Cookie.Values.Add("u_role", ds.Tables[0].Rows[0]["RoleID"].ToString());
                        Cookie.Values.Add("u_level", ds.Tables[0].Rows[0]["LevelID"].ToString());
                        Cookie.Values.Add("u_purview", ds.Tables[0].Rows[0]["ReadRight"].ToString() + //读权限
                                          ds.Tables[0].Rows[0]["WriteRight"].ToString() +             //写权限
                                          ds.Tables[0].Rows[0]["RefreshRight"].ToString() +
                                          ds.Tables[0].Rows[0]["FileRight"].ToString());              //刷新权限;

                        Response.AppendCookie(Cookie);
                        Response.Redirect("~/main.htm");
                    }
                }
                else
                {
                    Response.Redirect("../Login.aspx");
                }
            }
            else
            {
                txt_UserName.Focus();

                if (!Page.IsPostBack)
                {
                    if (Request.Cookies["Cookies"] != null)
                    {
                        HttpCookie mycookies = new HttpCookie("Cookies");
                        mycookies["u_id"] = null;
                        mycookies.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(mycookies);
                        txt_Pwd.Text = "";
                        SSOHelper.GlobalSessionEnd();
                    }
                }
            }
        }
    }