You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

427 lines
21 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.EntityDA;
using DSWeb.Models;
using System.Collections.Generic;
using System.Xml;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.Mobile.DAL;
namespace DSWeb
{
public partial class Login1 : System.Web.UI.Page
{
public string sSQL = String.Empty;
DB pDB = new DB();
Cookies cookie = new Cookies();
UserDA UserDA = new UserDA();
public string PageMeta = "";
protected void Page_Load(object sender, EventArgs e)
{
/*XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("vote.xml")); //加载xml
XmlNodeList NodeList = xmlDoc.SelectNodes("/vote/item"); //xml节点的路径
string xmlName = NodeList[0].ChildNodes[0].InnerText; //获取第一个Student节点的StuName
if (xmlName == "2") { Response.Redirect("Login_new.aspx"); }*/
this.Page.Title = "用户登录";
PageMeta = this.Page.Title;
if (!Page.IsPostBack)
{
if (Request.Cookies["Lan"] != null)
{
string sel = Server.UrlDecode(cookie.getCookie("Lan").ToString().Trim());
sel = sel.Replace("Lan=", "");
this.selLan.SelectedValue = sel;
}
if (Request.Cookies["isCheckBox"] != null)
{
if (Server.UrlDecode(cookie.getCookie("isCheckBox").ToString().Trim()) == "0")
{
this.CheckBox1.Checked = false;
}
else
{
this.CheckBox1.Checked = true;
if (Request.Cookies["COMPANYCODENAME"] != null)
{
this.list_subcompany.Text = Server.UrlDecode(cookie.getCookie("COMPANYCODENAME").ToString().Trim());
}
if (Request.Cookies["COMPANYNAME"] != null)
{
this.lb_subcompany.Value = Server.UrlDecode(cookie.getCookie("COMPANYNAME").ToString().Trim());
}
if (Request.Cookies["CODENAME"] != null)
{
this.list_CODENAME.Text = Server.UrlDecode(cookie.getCookie("CODENAME").ToString().Trim());
}
if (Request.Cookies["SHOWNAME"] != null)
{
this.lb_CODENAME.Value = Server.UrlDecode(cookie.getCookie("SHOWNAME").ToString().Trim());
}
if (Request.Cookies["PASSWORD"] != null && Server.UrlDecode(cookie.getCookie("PASSWORD").ToString().Trim()) != "")//Request.Cookies["PASSWORD"] != null && && Request.Cookies["RmbPassword"].ToString() == "1"
{
//tbpassword.Attributes.Add("value", Server.UrlDecode(cookie.getCookie("PASSWORD").ToString().Trim()));
//tbpassword.Value = Server.UrlDecode(cookie.getCookie("PASSWORD").ToString().Trim());
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>document.getElementById('tbpassword').value='" + Server.UrlDecode(cookie.getCookie("PASSWORD").ToString().Trim()) + "';</script>");
this.CheckBox2.Checked = true;
}
else
{
//tbpassword.Attributes.Add("value", "");
//this.tbpassword.Attributes.Remove("value");
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>document.getElementById('tbpassword').value='';</script>");
this.CheckBox2.Checked = false;
}
}
}
}
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("vote.xml")); //加载xml
XmlNodeList NodeList = xmlDoc.SelectNodes("/vote/password"); //xml节点的路径
string xmlName = NodeList[0].ChildNodes[0].InnerText; //获取第一个Student节点的StuName
if (xmlName == "1")
{
this.CheckBox2.Visible = true;
}
else
{
this.CheckBox2.Visible = false;
//this.tbpassword.Attributes.Remove("value");
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>document.getElementById('tbpassword').value='';</script>");
}
//加载下拉框
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>initComboSubcompany();</script>");
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (!this.CheckBox2.Checked)
{
Session["PASSWORD"] = "";
bool chk = cookie.setCookie("PASSWORD", "");
}
else
{
Session["PASSWORD"] = this.tbpassword.Value.Trim();
bool chk = cookie.setCookie("PASSWORD", Server.UrlEncode(this.tbpassword.Value.Trim()));
}
}
protected void btLogin_Click(object sender, EventArgs e)
{
string strCompanyCode = "";
string strCompanyName = "";
string strUserCodeName = "";
string strUserPassword = "";
strCompanyCode = this.list_subcompany.Text.Trim();
strCompanyName = this.lb_subcompany.Value.Trim();
strUserCodeName = this.list_CODENAME.Text.Trim();
strUserPassword = this.tbpassword.Value.Trim();
if (strCompanyCode.Equals("") || strUserCodeName.Equals("") || strUserPassword.Equals(""))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('公司名称、用户名、密码不能为空,请重新登陆!');history.back();</script>");
return;
}
if (strCompanyCode.IndexOf("'") >= 0)
{
strCompanyCode = strCompanyCode.Replace("'", " ");
}
if (strCompanyCode.IndexOf("'") >= 0)
{
strUserCodeName = strUserCodeName.Replace("'", " ");
}
if (strCompanyCode.IndexOf("'") >= 0)
{
strUserPassword = strUserPassword.Replace("'", " ");
}
UserEntity userEntity = new UserEntity();
UserDA userDA = new UserDA();
userEntity = userDA.GetSigleUserInfoBySignIn(strUserCodeName, strUserPassword, strCompanyCode);
CompanyEntity companyEntity = new CompanyEntity();
CompanyDA companyDA = new CompanyDA();
if (userEntity != null)
{
if (userEntity.Gid != null)
{
if (!userEntity.IsDeleted)
{
UserAttributeDA userAttributeDA = new UserAttributeDA();
UserAttributeEntity userAttributeEntity = new UserAttributeEntity();
userAttributeEntity = userAttributeDA.GetUserAttributeByIdAndAttrName(userEntity.Gid, "isUseSystem");
if (userAttributeEntity != null)
{
if (userAttributeEntity.Gid != null)
{
if (userAttributeEntity.RefEntity.AttributeValue.ToString().Trim().ToLower().Equals("true"))
{
Session["USERID"] = userEntity.Gid;
Session["CODENAME"] = userEntity.CodeName;
Session["SHOWNAME"] = userEntity.ShowName;
Session["PASS"] = userEntity.PassWord;
if (this.CheckBox2.Checked)
{
Session["PASSWORD"] = userEntity.PassWord;
}
else
{
Session["PASSWORD"] = "";
}
if (this.selLan.SelectedValue == "Chinese")
{
Session["LANGUAGES"] = "zh-cn";
}
else if (this.selLan.SelectedValue == "English")
{
Session["LANGUAGES"] = "en-us";
}
if (!strCompanyCode.Trim().Equals(""))
{
companyEntity = companyDA.GetCompanyByCodeNameNoLogoImg(strCompanyCode.ToUpper());
if (companyEntity != null)
{
if (companyEntity.GID != null)
{
Session["COMPANYID"] = companyEntity.GID;
Session["COMPANYNAME"] = companyEntity.NAME;
Session["LOCALCURR"] = companyEntity.LOCALCURR;
Session["WORKFLOWMSG"] = companyEntity.WORKFLOWMSG;
}
}
}
Session["DEPTNAME"] = UserDA.GetUserDepartmentName(userEntity.Gid);
Session["DEPTGID"] = UserDA.GetDEPTGID(userEntity.Gid);
//Record User SignIn System
UserLoginStatusDA userLoginStatusDA = new UserLoginStatusDA();
UserLoginStatusEntity userLoginStatusEntity = new UserLoginStatusEntity();
//查看是否当前登录用户是否是时效内重新登录的用户
userLoginStatusEntity = userLoginStatusDA.GetLoginStatusByUserID(Session["USERID"].ToString());
if (userLoginStatusEntity.GID != null)
{
DateTime signDateTime = userLoginStatusEntity.SignInTime;
DateTime serverDateTime = userLoginStatusEntity.ServerDateTime;
double expiresMinutes = double.Parse(userLoginStatusEntity.ExpiresMinutes.ToString());
if (signDateTime.AddMinutes(expiresMinutes).CompareTo(serverDateTime) >= 0)
{
userLoginStatusDA.DeleteUserLoginStatus(userLoginStatusEntity.GID);
userLoginStatusEntity.GID = Guid.NewGuid().ToString();
userLoginStatusEntity.SessionID = "USERID";
userLoginStatusEntity.ExpiresMinutes = 200;
userLoginStatusDA.InsertLoginStatus(userLoginStatusEntity);
}
else
{
userLoginStatusDA.UpdateLoginStatusForReSign(userLoginStatusEntity);
}
}
else
{
userLoginStatusEntity.GID = Guid.NewGuid().ToString();
userLoginStatusEntity.SessionID = Guid.NewGuid().ToString();
userLoginStatusEntity.UserID = Session["USERID"].ToString();
userLoginStatusEntity.ExpiresMinutes = 200;
userLoginStatusDA.InsertLoginStatus(userLoginStatusEntity);
}
//HomeService.HomeService.StoreMemcachedForLogin(userEntity.CodeName);
// HomeService.HomeService.StoreMemcachedForUser(userEntity.CodeName, userEntity.Gid, userEntity.ShowName, companyEntity.GID, strCompanyCode, companyEntity.NAME, companyEntity.LOCALCURR, companyEntity.WORKFLOWMSG, Session["DEPTGID"].ToString(), Session["DEPTNAME"].ToString());
bool ck0 = cookie.setCookie("DSUSERID", Server.UrlEncode(userEntity.Gid));
ck0 = cookie.setCookie("COMPANYCODENAME", Server.UrlEncode(strCompanyCode));
ck0 = cookie.setCookie("COMPANYNAME", Server.UrlEncode(companyEntity.NAME));
ck0 = cookie.setCookie("COMPANYID", Server.UrlEncode(companyEntity.GID));
ck0 = cookie.setCookie("LOCALCURR", Server.UrlEncode(companyEntity.LOCALCURR));
ck0 = cookie.setCookie("WORKFLOWMSG", Server.UrlEncode(companyEntity.WORKFLOWMSG));
ck0 = cookie.setCookie("CODENAME", Server.UrlEncode(userEntity.CodeName));
ck0 = cookie.setCookie("SHOWNAME", Server.UrlEncode(userEntity.ShowName));
T_ALL_DA T_ALL_DA = new T_ALL_DA();
var PARAMVALUE = T_ALL_DA.GetStrSQL("PARAMVALUE", "select top 1 PARAMVALUE from sys_param_set where PARAMNAME='SALESUBMITFEE' ");
ck0 = cookie.setCookie("ISSALEWORK", Server.UrlEncode(PARAMVALUE));
PARAMVALUE = T_ALL_DA.GetStrSQL("PARAMVALUE", "select top 1 PARAMVALUE from sys_param_set where PARAMNAME='ISENABLECUSTRANGE' ");
ck0 = cookie.setCookie("ISENABLECUSTRANGE", Server.UrlEncode(PARAMVALUE));
PARAMVALUE = T_ALL_DA.GetStrSQL("PARAMVALUE", "select top 1 PARAMVALUE from sys_param_set where PARAMNAME='USEHOMEPAGE' ");
ck0 = cookie.setCookie("USEHOMEPAGE", Server.UrlEncode(PARAMVALUE));
if (this.CheckBox2.Checked)
{
ck0 = cookie.setCookie("PASSWORD", Server.UrlEncode(userEntity.PassWord));
}
else
{
ck0 = cookie.setCookie("PASSWORD", "");
}
if (this.CheckBox1.Checked)
{
ck0 = cookie.setCookie("isCheckBox", Server.UrlEncode("1"));
}
else
{
ck0 = cookie.setCookie("isCheckBox", Server.UrlEncode("0"));
}
#region 判断IP限制
string msg = iplimitDo(userEntity.Gid);
if (msg != "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('登录IP已被限制');document.getElementById('lb_CODENAME').innerHTML = '';history.back();</script>");
return;
}
#endregion
Response.Redirect("~/Default.aspx");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('账户已禁用,请联系管理员');history.back();</script>");
return;
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('用户名不存在,或用户名、密码错误,请重新登陆!');document.getElementById('lb_CODENAME').innerHTML = '';history.back();</script>");
return;
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('用户名不存在,或用户名、密码错误,请重新登陆!');document.getElementById('lb_CODENAME').innerHTML = '';history.back();</script>");
return;
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('用户名不存在,或用户名、密码错误,请重新登陆!');document.getElementById('lb_CODENAME').innerHTML = '';history.back();</script>");
return;
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('用户名不存在,或用户名、密码错误,请重新登陆!');document.getElementById('lb_CODENAME').innerHTML = '';history.back();</script>");
return;
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('用户名不存在,或用户名、密码错误,请重新登陆!');document.getElementById('lb_CODENAME').innerHTML = '';history.back();</script>");
return;
}
}
protected void lnkTo_Click(object sender, EventArgs e)
{
XmlDocument objXmlDoc = new XmlDocument();
objXmlDoc.Load(Server.MapPath("vote.xml"));
objXmlDoc.SelectSingleNode("/vote/item").InnerText = "2";
objXmlDoc.Save(Server.MapPath("vote.xml"));
Response.Redirect("Login_new.aspx");
}
protected void selLan_SelectedIndexChanged(object sender, EventArgs e)
{
//Request.Cookies["Lan"].Value=this.selLan.SelectedItem.Value;
//Response.Cookies["Lan"].Value = this.selLan.SelectedItem.Value;
bool ck0 = cookie.setCookie("Lan", Server.UrlEncode(this.selLan.SelectedItem.Value));
}
private string iplimitDo(string userid)
{
string message = "";
try
{
var IPLimit = MsSysParamSetDAL.GetData("PARAMNAME='IPLimit'");
//是否限制IP登录
if (IPLimit.PARAMVALUE == "1")
{
message = checkIp(userid);
}
}
catch (Exception)
{
throw;
}
return message;
}
private string checkIp(string userid)
{
string message = "";
string sql = "select ip from sys_iplimit where oper is not null and oper <> ''";
Database db = DatabaseFactory.CreateDatabase();
string ips = "";
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
ips += reader["ip"].ToString() + ",";
}
}
ips = ips.Length > 0 ? ips.Substring(0, ips.Length - 1) : "";
if (ips == "")
{
message = "未获取到公司IP地址";
}
else
{
//判断用户权限是否需要ip登录验证
string sql2 = "select count(*) from user_action where USERID = '" + userid
+ "' AND ACTIONID = '77761145-C3A8-46D4-9FE4-746A805244B0'";
int rst = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, sql2));
if (rst > 0)
{
//验证ip
string clientIP = HttpContext.Current.Request.UserHostAddress;
DBLog.Log(clientIP);
if (!ips.Contains(clientIP))
{
message = "IP已被限制";
}
}
else
{
//不验证ip
}
}
return message;
}
}
}