Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Url   = Request["user"] + "";
            string sign  = Request["sign"] + "";
            string valid = Request["valid"] + "";

            if (sign == "-1" || valid == "-1" || Url == "加密失败")
            {
                this.pError.InnerHtml = "登录信息异常!";
                return;
            }

            //解密
            string userUrl = new AESHelper().KeyDecrypt(sign, valid, Url);

            if (userUrl == "-1")
            {
                this.pError.InnerHtml = "认证过期!";
                return;
            }
            else if (userUrl == "-2")
            {
                this.pError.InnerHtml = "认证异常!";
                return;
            }

            JsonData JInfo = JsonMapper.ToObject(userUrl);

            if (JInfo["username"].ToString() != "" && JInfo["password"].ToString() != "")
            {
                type     = JInfo["type"].ToString();
                username = JInfo["username"].ToString();
                password = JInfo["password"].ToString();
                logo     = JInfo["logo"].ToString();
                //add by hgh
                compid = JInfo["compid"].ToString();
            }
            else
            {
                this.pError.InnerHtml = "url参数不能为空!";
                return;
            }

            if (!DBHelper.IsOpen())
            {
                this.pError.InnerHtml = "-系统无法连接数据库服务器,请联系管理员!";
                return;
            }
            List <Hi.Model.SYS_CompUser> ListCompUser = null;
            List <Hi.Model.SYS_Users>    ListUsers    = null;

            ListUsers = new Hi.BLL.SYS_Users().GetListUser("top 1 *", "Username", username, "");
            if (ListUsers.Count > 0)
            {
                if (ListUsers.Where(T => T.IsEnabled == 1).ToList().Count == 0)
                {
                    this.pError.InnerHtml = "用户已被禁用!";
                    return;
                }
                if (Util.md5(Password) != ListUsers[0].UserPwd)
                {
                    //登录录日志
                    Utils.EditLog("安全日志", Username, "用户" + Username + "登录管理系统失败,密码错误。", "系统安全模块", loginUrl, 0, 0, ListUsers[0].Type);
                    this.pError.InnerHtml = "登录密码错误!";
                    return;
                }
                ListCompUser = new Hi.BLL.SYS_CompUser().GetList("*", " dr=0 and Compid='" + compid + "' and Userid=" + ListUsers[0].ID + "", " createdate ");
                if (ListCompUser.Count > 0)
                {
                    if (ListCompUser.Where(T => T.IsEnabled == 1).ToList().Count == 0)
                    {
                        //登录录日志
                        //Utils.EditLog("安全日志", Username, "用户" + Username + "登录管理系统失败,用户帐号所有角色已被禁用。", "系统安全模块", loginUrl, 0, 0, ListCompUser[0].UType);
                        this.pError.InnerHtml = "您的账户已被禁用!";
                        return;
                    }
                }
                else
                {
                    //登录录日志
                    //Utils.EditLog("安全日志", Username, "用户" + Username + "登录管理系统失败,用户明细表(SYS_CompUser)异常。", "系统安全模块", loginUrl, 0, 0, ListCompUser[0].UType);
                    //Msg.Msg = "用户异常,请联系网站客服!";
                    this.pError.InnerHtml = "用户名或密码错误!";
                    return;
                }

                //UserLogin(ListUsers[0]);
                Hi.Model.SYS_Users User   = ListUsers[0];
                LoginModel         Umodel = new LoginModel();
                //Umodel.Url = loginUrl;
                if (compid == "1203")
                {
                    Umodel.Url = "/jlc/";
                }
                Umodel.UserName = User.UserName;
                Umodel.TrueName = User.TrueName;
                Umodel.UserID   = User.ID;
                Umodel.TypeID   = ListCompUser[0].UType;
                Umodel.Ctype    = ListCompUser[0].CType;
                Umodel.CompID   = ListCompUser[0].CompID;
                Umodel.DisID    = ListCompUser[0].DisID;
                Umodel.Phone    = User.Phone;
                Umodel.CUID     = Common.DesEncrypt(ListCompUser[0].ID.ToString(), Common.EncryptKey);
                //Umodel.IsPhoneLogin = IsphoneLogin;
                Session.Remove("UserModel");
                //string sql = "select rf.FunCode from SYS_RoleSysFun rf join SYS_CompUser u on u.RoleID=rf.RoleID  where u.UserID=" + User.ID;
                //DataTable dt = SqlHelper.Query(SqlHelper.LocalSqlServer, sql).Tables[0];
                //var query = dt.AsEnumerable().Select(t => t.Field<string>("FunCode"));
                //string Code = string.Join(",", query);
                //Umodel.UserPowerCode = Code;
                Session["UserModel"] = Umodel;

                //if (Umodel.TypeID.ToString() == "1" || Umodel.TypeID.ToString() == "5")//代理商
                //{
                //    Response.Redirect("/Distributor/UserIndex.aspx");
                //}
                if (Umodel.TypeID.ToString() == "3" || Umodel.TypeID.ToString() == "4")//厂商
                {
                    Response.Redirect("/Company/jsc.aspx");
                }
                else
                {
                    Response.Redirect("/Distributor/UserIndex.aspx");
                }

                Utils.EditLog("安全日志", User.UserName, "用户" + User.UserName + "登录管理系统成功。", "系统安全模块", loginUrl, 0, 1, ListCompUser[0].UType);

                HttpCookie cookie = new HttpCookie("loginmodel", System.Web.HttpUtility.UrlEncode(User.UserName));
                cookie.Expires  = DateTime.Now.AddDays(7);
                cookie.HttpOnly = true;
                Response.Cookies.Add(cookie);
            }
            else
            {
                this.pError.InnerHtml = "用户名或密码错误!";
                return;
            }
        }
    }
Exemplo n.º 2
0
 public void LoginHTML(string Userid, int type)
 {
     if (!string.IsNullOrWhiteSpace(Userid))
     {
         WriteHTML = "  <div class=\"pageLogin\" id=\"AccountSwitch\" >	<div class=\"role-cur\"> ";
         List <Hi.Model.SYS_CompUser> ListCompUser = new Hi.BLL.SYS_CompUser().GetList("id,compid,Disid,Ctype,Utype", " isnull(dr,0)=0 and IsAudit=2 and IsEnabled=1 and userid  in(" + Userid + ")", "");
         if (ListCompUser.Count > 0)
         {
             string Compid = string.Join(",", ListCompUser.Where(T => T.CType == 1 && (T.UType == 3 || T.UType == 4)).ToList().Select(T => T.CompID));
             if (Compid != "")
             {
                 List <Hi.Model.BD_Company> ListComp = new Hi.BLL.BD_Company().GetList("ID,CompName", " isnull(dr,0)=0 and AuditState=2 and IsEnabled=1 and ID in(" + Compid + ")", "createdate");
                 if (ListComp.Count > 0)
                 {
                     WriteHTML += (ListComp.Count > 0 ? "<div class=\"title\"><i class=\"hx-i\"></i>厂商</div> <div class=\"list\">" : "");
                     string CompHTML = "";
                     foreach (Hi.Model.BD_Company model in ListComp)
                     {
                         CompHTML += "<a href=\"javascript:;\" type=" + type + "  title='" + model.CompName + "' tip='" + Common.DesEncrypt(ListCompUser.Where(T => T.CType == 1 && T.CompID == model.ID).ToList()[0].ID.ToString(), Common.EncryptKey) + "'>" + model.CompName + "</a>";
                     }
                     WriteHTML += CompHTML;
                     WriteHTML += (ListComp.Count > 0 ? "</div>" : "");
                 }
             }
             ListCompUser = ListCompUser.Where(T => T.CType == 2 && (T.UType == 1 || T.UType == 5)).ToList();
             string DisID = string.Join(",", ListCompUser.Select(T => T.DisID));
             Compid = string.Join(",", ListCompUser.ToList().Select(T => T.CompID));
             if (DisID != "" && Compid != "")
             {
                 List <Hi.Model.BD_Distributor> ListDis  = new Hi.BLL.BD_Distributor().GetList("ID,DisName,CompID", " isnull(dr,0)=0 and AuditState=2 and IsEnabled=1 and ID in(" + DisID + ")", "createdate");
                 List <Hi.Model.BD_Company>     ListComp = new Hi.BLL.BD_Company().GetList("ID,CompName", " isnull(dr,0)=0  and ID in(" + Compid + ")", "createdate");
                 if (ListDis.Count > 0 && ListComp.Count > 0)
                 {
                     WriteHTML += (ListDis.Count > 0 ? "<div class=\"title\"><i class=\"jx-i\"></i>代理商</div> <div class=\"list\">" : "");
                     string CompHTML = "";
                     foreach (Hi.Model.BD_Distributor model in ListDis)
                     {
                         string Name = "";
                         if (ListComp.Where(T => T.ID == model.CompID).ToList().Count > 0)
                         {
                             Name = ListComp.Where(T => T.ID == model.CompID).ToList()[0].CompName;
                         }
                         CompHTML += "<a href=\"javascript:;\" title='" + (Name) + "' type=" + type + "  tip='" + Common.DesEncrypt(ListCompUser.Where(T => T.CType == 2 && T.DisID == model.ID).ToList()[0].ID.ToString(), Common.EncryptKey) + "'>" + (Name) + "</a>";
                     }
                     WriteHTML += CompHTML;
                     WriteHTML += (ListDis.Count > 0 ? "</div>" : "");
                 }
             }
             //Compid = string.Join(",", ListCompUser.Where(T => T.CType == 2 && (T.UType == 1 || T.UType == 5)).ToList().Select(T => T.CompID));
             //if (Compid != "")
             //{
             //    List<Hi.Model.BD_Company> ListComp = new Hi.BLL.BD_Company().GetList("ID,CompName", " isnull(dr,0)=0 and AuditState=2 and IsEnabled=1 and ID in(" + Compid + ")", "createdate");
             //    WriteHTML += (ListComp.Count > 0 ? "<div class=\"title\"><i class=\"hx-i\"></i>代理商</div> <div class=\"list\">" : "");
             //    string CompHTML = "";
             //    foreach (Hi.Model.BD_Company model in ListComp)
             //    {
             //        if (string.IsNullOrEmpty(CompHTML))
             //        {
             //            CompHTML += "<a href=\"javascript:;\" title='" + model.CompName + "'  tip='" + Common.DesEncrypt(ListCompUser.Where(T => T.CType == 2 && T.CompID == model.ID).ToList()[0].ID.ToString(), Common.EncryptKey) + "'>" + model.CompName + "</a>";
             //        }
             //        else
             //        {
             //            CompHTML += "<i>|</i><a href=\"javascript:;\" title='" + model.CompName + "' tip='" + Common.DesEncrypt(ListCompUser.Where(T => T.CType == 2 && T.CompID == model.ID).ToList()[0].ID.ToString(), Common.EncryptKey) + "' >" + model.CompName + "</a>";
             //        }
             //    }
             //    WriteHTML += CompHTML;
             //    WriteHTML += (ListComp.Count > 0 ? "</div>" : "");
             //}
         }
         else
         {
             WriteHTML += "用户没有绑定任何企业。";
         }
         WriteHTML += "	</div><div class=\"bg\"></div></div>";
     }
 }