Files
jlzx/jlzx-single/docs/pageoffice/ca/Login.aspx.cs
2022-07-25 11:09:12 +08:00

336 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using hyplat.bean.sysconfig;
using hyplat.biz;
using hyplat.biz.service.orgcode;
using hyplat.biz.service.sysconfig;
using hyplat.biz.service.user;
using hyplat.utilities;
using System.Web.UI.WebControls;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using SSOAgentLibrary.client.filter;
public partial class Login : System.Web.UI.Page
{
protected static string loginLeft = "images/loginImgs/bg_left.jpg";
protected static string versionTitle = "";
protected string issignature = "none";
protected string iscertlogin = "false";
UserLoginTimeService ulservice = ServiceManager.getServiceBean("UserLoginTimeService") as UserLoginTimeService;
private UserCaService userCaS = ServiceManager.getServiceBean("UserCaService") as UserCaService;
protected void Page_Load(object sender, EventArgs e)
{
//神州融信单点登录
//AuthenFilter authenfilter = new AuthenFilter();
//authenfilter.doFilter(Request);
//if (Session["UserID"] != null && Session["UserID"].ToString().Length > 0)
//{
// Response.Redirect("Default.aspx");
//}
//是否签章验证
iscertlogin = DictionaryClass.getValue("是否证书登录");
if (iscertlogin == "true")
issignature = "";
if (!IsPostBack)
{
//不知道干什么用11.26mtl暂时删除
//if (Request.QueryString["userName"] != null && Request.QueryString["userPassword"] != null)
// {
// txtUserName.Text = Server.UrlDecode(Request.QueryString["userName"].ToString());
// txtUserPassword.Text = Server.UrlDecode(Request.QueryString["userPassword"].ToString());
// userLoginChecked();
// }
//打开页面时先生成一个随机数发给客户端并保存到session中。
Random r = new Random();
String random = RandomString.Next();
Session["random"] = random;
msg.Text = random.ToString();
}
//随机字符串
Session["solt"] = RandomString.Next();
hidsolt.Value = Session["solt"].ToString();
imgBtn.ImageUrl = "ImageCodeValidate.aspx";
}
protected void ImgBtnClear_Click(object sender, ImageClickEventArgs e)
{
clearLoginContent();
}
protected void ImgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
string code = validatechar.Text;
HttpCookie htco = Request.Cookies["ImageV"];
string scode = htco.Value.ToString();
if (code != scode)
{
MessageBox.Show("验证码输入不正确,请重新输入!", Page);
validatechar.Text = "";
}
else
{
userLoginChecked();
}
}
/// <summary>
/// 清空登录的文本框并让用户名文本框获得焦点以便用户重新输入
/// </summary>
protected void clearLoginContent()
{
txtUserName.Text = string.Empty;
txtUserPassword.Text = string.Empty;
txtUserName.Focus();
}
/// <summary>
/// 登录信息验证的方法
/// </summary>
protected void userLoginChecked()
{
if (Session["solt"].ToString() != hidsolt.Value)
{
return;
}
Session["solt"] = null;
string userName = txtUserName.Text.Trim();
//特殊情况可以不用证书登录
bool isSpecial = userName.Contains("_hebqts@yxt");
//解密页面上传过来的密码
//string userPassword = hyplat.utilities.EncryptionTool.GetDecodeString(txtUserPassword.Text.Trim());
//加密密码与数据库中的对比
string userPassword = hyplat.utilities.EncryptionTool.BBS_MD5_Encrypt(txtUserPassword.Text.Trim(), 32);
if (userName != string.Empty && userPassword != string.Empty)
{
UserService uService = (UserService)ServiceManager.getServiceBean("UserService");
DataTable dtLoginUser = uService.getUserForLogin(userName);
if (dtLoginUser != null && dtLoginUser.Rows.Count > 0)
{
string userOrg = dtLoginUser.Rows[0]["OrgID"].ToString();
OrgCodeService codeServide = ServiceManager.getServiceBean("OrgCodeService") as OrgCodeService;
string localOrg = codeServide.getLocalCode();
if (userOrg != "0" && userOrg != localOrg)
{
lblLoginMsg.Text = "请核对您登录的服务器是否正确";
return;
}
}
else
{
lblLoginMsg.Text = "用户名或密码错误!";
return;
}
//特殊情况可以不用证书登录
if (!isSpecial)
{
DictionaryService DicSer = ServiceManager.getServiceBean("DictionaryService") as DictionaryService;
string value = DictionaryClass.getIsSignature(dtLoginUser.Rows[0]["RoleID"].ToString());
if (value == "true")
{
DataTable dtCa = userCaS.GetByUserId(dtLoginUser.Rows[0]["ID"].ToString());
if (dtCa != null && dtCa.Rows.Count > 0)
{
if (dtCa.Rows[0]["ca"].ToString() != "hebqts_commonuser")
{
MessageBox.Show("已绑定数字证书,请使用数字证书登录!", Page);
return;
}
}
}
}
//需要有一个非法字符的判断
int result = 0;
lblLoginMsg.Text = string.Empty;
result = ulservice.LoginControl(userName, userPassword,HttpContext.Current.Request.UserHostAddress);
//登录成功
if (1 == result)
{
//是否允许重复登陆读写配置文件中的项1为不允许其他为允许mtl20170422
string filterStr = System.Configuration.ConfigurationManager.AppSettings["hebqts_onlylogin"];
if (filterStr == "1")
{
if (dtLoginUser.Rows[0]["Status"].ToString() == "01")
{
lblLoginMsg.Text = "您已经登陆,不能重复登陆。";
return;
}
}
LoginLogic.LoginInit(dtLoginUser);
if (Request.QueryString["type"] != null)
Response.Redirect("Default.aspx?type=" + Request.QueryString["type"].ToString());
else
Response.Redirect("Default.aspx");
//Response.Redirect("TreeTest.aspx");
//Response.Redirect("Index.aspx");
//Response.Redirect("iso9000/isoFiles/IsoFilesCollection.aspx");
//Response.Redirect("office/sendfile/sendfile.aspx");
//return;
}
if (0 == result)
{
lblLoginMsg.Text = "用户或密码错误,请核对";
return;
}
//默认密码登录,请修改密码
if (-6 == result)
{
Session["checkstr"] = System.DateTime.Now.ToString();
Response.Redirect("AlterPassword.aspx?UserName=" + userName);
return;
}
//网络连接失败
if (-90 == result)
{
lblLoginMsg.Text = "网络连接失败,请稍候重试!";
return;
}
//网络连接失败
if (-99 == result)
{
lblLoginMsg.Text = "未知错误!";
return;
}
ErrorControl(dtLoginUser.Rows[0]["ID"].ToString(),result);
}
else
{
lblLoginMsg.Text = "用户名和密码不允许为空 ";
}
}
private void ErrorControl(string userId,int error)
{
//用户名或者密码不正确
DataTable dtul = ulservice.getUserLoginTimeByUserID(userId);
if (dtul != null && dtul.Rows.Count > 0)
{
int errorcount = Convert.ToInt32(ulservice.getLoginErrorQuantity()) - Convert.ToInt32(dtul.Rows[0]["ErrorQuantity"]);
if (error == -1)
{
lblLoginMsg.Text = "输入用户名或密码错误。";
//if (errorcount > 0)
lblLoginMsg.Text += "您还有 " + errorcount.ToString() + " 次机会可以登陆到系统";
}
if (error == -9)
{
int lockMinutes = Convert.ToInt32(ulservice.getLockTime());
int errorTimes = DateTool.DateDiff(DateTime.Now, Convert.ToDateTime(dtul.Rows[0]["LastErrorTime"]), "minute");
lblLoginMsg.Text = "对不起,您的账户已经锁定,在 " + (lockMinutes-errorTimes).ToString() + " 分钟后才可以重新登陆到系统。<br />如果您忘记密码请联系管理员!";
txtUserName.Enabled = false;
txtUserPassword.Enabled = false;
ImgBtnLogin.Enabled = false;
}
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
Response.Buffer = true;
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("SOA中间件安装SOAOfficeSetup.rar"));
Response.ContentType = "application/octet-stream";
Response.WriteFile("~/soasetup/download.rar");
Response.Flush();
Response.End();
}
catch (Exception)
{
}
}
protected void btnCa_Click(object sender, EventArgs e)
{
//从session中获取随机数
if (Session["random"] == null)
{
MessageBox.Show("验签失败:操作超时,请重新登录", Page);
return;
}
String random = msg.Text;
//LogFile.log(random + "点击登陆", "时间:" + DateTime.Now);
//联系svs服务器进行验证
int result = BLL.SvsManager.VerifyCertSign(Encoding.ASCII.GetBytes(random), signCert.Text, signature.Text);
if (result != 0) //认证失败
{
string strResult = "验证失败:";
switch (result)
{
case -1:
strResult += "(无法连接svs服务器)";
break;
case 2:
strResult += "(证书已经过期,需要延期后才能使用)";
break;
case -6805:
strResult += "(无效的证书文件)";
break;
case -6406:
strResult += "(签名验证失败)";
break;
default:
strResult += "(errorcode:" + result + ")";
break;
}
MessageBox.Show(strResult, Page);
}
else
{
//解析证书获取CN
X509Certificate2 xcert = new X509Certificate2(Encoding.ASCII.GetBytes(signCert.Text));
DN dn = new DN(xcert.Subject);
String cn = dn.CommonName;
String gName = dn.GivenName;
String uniqueCode = gName;
if (cn.Length > gName.Length)
{
uniqueCode = cn;
}
//LogFile.log(random+"验证成功", "时间:" + DateTime.Now);
UserService uservice = ServiceManager.getServiceBean("UserService") as UserService;
DataTable dtLoginUser = uservice.GetLoginByCA(uniqueCode);
if (dtLoginUser != null && dtLoginUser.Rows.Count > 0)
{
LoginLogic.LoginInit(dtLoginUser);
Response.Redirect("Default.aspx");
}
else
{
MessageBox.Show("证书还没有绑定用户!", Page);
}
}
}
}