298 lines
12 KiB
C#
298 lines
12 KiB
C#
|
using NGTools.Tools;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using System.Web;
|
|||
|
|
|||
|
namespace NGTools.ASHX
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// login 的摘要说明
|
|||
|
/// </summary>
|
|||
|
public class login : IHttpHandler
|
|||
|
{
|
|||
|
|
|||
|
public void ProcessRequest(HttpContext context)
|
|||
|
{ JsEncryptHelper jsHelper = new JsEncryptHelper();
|
|||
|
string a = "";
|
|||
|
string b = "";
|
|||
|
string userName = "";
|
|||
|
string passWord = "";
|
|||
|
context.Response.ContentType = "text/plain";
|
|||
|
|
|||
|
if (context.Request["action"] == "login")
|
|||
|
{
|
|||
|
context.Response.ContentType = "text/plain";
|
|||
|
|
|||
|
if (context.Request.QueryString["UID"] != "")
|
|||
|
{
|
|||
|
a = context.Request.QueryString["UID"];
|
|||
|
b = context.Request.QueryString["P"];
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
|
|||
|
{
|
|||
|
a = context.Request["username"] + "";
|
|||
|
b = context.Request["passwd"] + "";
|
|||
|
}
|
|||
|
|
|||
|
userName = jsHelper.Decrypt(a);
|
|||
|
passWord = jsHelper.Decrypt(b);
|
|||
|
|
|||
|
|
|||
|
string json = "";
|
|||
|
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'");
|
|||
|
if (dtUser.Rows.Count > 0)
|
|||
|
{
|
|||
|
if (dtUser.Rows[0]["loginflag"].ToString() == "0" || dtUser.Rows[0]["loginflag"].ToString() == "")
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
if (dtUser.Rows[0]["pswd"].ToString() == passWord)
|
|||
|
{
|
|||
|
context.Session["userName"] = dtUser.Rows[0]["user_name"].ToString(); ; //用户名
|
|||
|
context.Session["userAccount"] = dtUser.Rows[0]["user_account"].ToString(); //用户账号
|
|||
|
context.Session["userOrgID"] = dtUser.Rows[0]["ORG_ID"].ToString(); ;//所属单位ID
|
|||
|
context.Session["userRole"] = dtUser.Rows[0]["role"].ToString(); ;//用户角色
|
|||
|
context.Session["userAuthority"] = dtUser.Rows[0]["authority"].ToString(); //用户权限
|
|||
|
context.Session["phoneNo"] = dtUser.Rows[0]["phoneNo"].ToString(); //用户电话
|
|||
|
context.Session["regDateTime"] = dtUser.Rows[0]["regDateTime"].ToString(); //用户电话
|
|||
|
|
|||
|
string strSQL = "update user set loginflag='1' ,logintime='" + DateTime.Now + "' where user_name='" + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'";
|
|||
|
int num = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
context.Session.Timeout = 5;
|
|||
|
|
|||
|
|
|||
|
strSQL = "insert into loginrecord (user_id,login_DateTime,IP) values (" + "'" + dtUser.Rows[0]["user_account"].ToString() + "','" + DateTime.Now + "')";
|
|||
|
num = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
|
|||
|
//string Json = "[{";
|
|||
|
//Json += "\"statue\":\"OK\"," + "\"userName\":\"" + dtUser.Rows[0]["user_name"].ToString() + "\",";
|
|||
|
//Json += "\"userAccount\":\"" + dtUser.Rows[0]["user_account"].ToString() + "\",";
|
|||
|
//Json += "\"userOrgID\":\"" + dtUser.Rows[0]["ORG_ID"].ToString() + "\",";
|
|||
|
//Json += "\"regDateTime\":\"" + dtUser.Rows[0]["regDateTime"].ToString() + "\"}]";
|
|||
|
|
|||
|
json = "OK";
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "密码错误,请仔细想想....";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "这个账户在别的客户端已登录";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "没有这个用户,请仔细想想你注册时用名字....";
|
|||
|
}
|
|||
|
context.Response.Write(json);
|
|||
|
context.Response.End();
|
|||
|
}
|
|||
|
|
|||
|
if (context.Request["action"] == "loginMobile")
|
|||
|
{
|
|||
|
context.Response.ContentType = "text/plain";
|
|||
|
|
|||
|
userName = context.Request.QueryString["UID"];
|
|||
|
passWord = context.Request.QueryString["P"];
|
|||
|
|
|||
|
|
|||
|
string json = "";
|
|||
|
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'");
|
|||
|
if (dtUser.Rows.Count > 0)
|
|||
|
{
|
|||
|
if (dtUser.Rows[0]["loginflag"].ToString() == "0" || dtUser.Rows[0]["loginflag"].ToString() == "")
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
if (dtUser.Rows[0]["pswd"].ToString() == passWord)
|
|||
|
{
|
|||
|
context.Session["userName"] = dtUser.Rows[0]["user_name"].ToString(); ; //用户名
|
|||
|
context.Session["userAccount"] = dtUser.Rows[0]["user_account"].ToString(); //用户账号
|
|||
|
context.Session["userOrgID"] = dtUser.Rows[0]["ORG_ID"].ToString(); ;//所属单位ID
|
|||
|
context.Session["userRole"] = dtUser.Rows[0]["role"].ToString(); ;//用户角色
|
|||
|
context.Session["userAuthority"] = dtUser.Rows[0]["authority"].ToString(); //用户权限
|
|||
|
context.Session["phoneNo"] = dtUser.Rows[0]["phoneNo"].ToString(); //用户电话
|
|||
|
context.Session["regDateTime"] = dtUser.Rows[0]["regDateTime"].ToString(); //用户电话
|
|||
|
|
|||
|
string strSQL = "update user set loginflag='1' ,logintime='" + DateTime.Now + "' where user_name='" + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'";
|
|||
|
int num = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
context.Session.Timeout = 5;
|
|||
|
|
|||
|
|
|||
|
strSQL = "insert into loginrecord (user_id,login_DateTime,IP) values (" + "'" + dtUser.Rows[0]["user_account"].ToString() + "','" + DateTime.Now + "')";
|
|||
|
num = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
|
|||
|
//string Json = "[{";
|
|||
|
//Json += "\"statue\":\"OK\"," + "\"userName\":\"" + dtUser.Rows[0]["user_name"].ToString() + "\",";
|
|||
|
//Json += "\"userAccount\":\"" + dtUser.Rows[0]["user_account"].ToString() + "\",";
|
|||
|
//Json += "\"userOrgID\":\"" + dtUser.Rows[0]["ORG_ID"].ToString() + "\",";
|
|||
|
//Json += "\"regDateTime\":\"" + dtUser.Rows[0]["regDateTime"].ToString() + "\"}]";
|
|||
|
|
|||
|
json = "OK";
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "密码错误,请仔细想想....";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "这个账户在别的客户端已登录";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "没有这个用户,请仔细想想你注册时用名字....";
|
|||
|
}
|
|||
|
context.Response.Write(json);
|
|||
|
context.Response.End();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
if (context.Request["action"] == "modPass")
|
|||
|
{
|
|||
|
|
|||
|
context.Response.ContentType = "text/plain";
|
|||
|
|
|||
|
//string userName = context.Request.Form["username"];
|
|||
|
//string oldpasswd = context.Request.Form["oldpasswd"];
|
|||
|
//string newpasswd = context.Request.Form["newpasswd"];
|
|||
|
|
|||
|
|
|||
|
a = context.Request["username"] + "";
|
|||
|
b = context.Request["oldpasswd"] + "";
|
|||
|
string c = context.Request["newpasswd"] + "";
|
|||
|
userName = jsHelper.Decrypt(a);
|
|||
|
string oldpasswd = jsHelper.Decrypt(b);
|
|||
|
string newpasswd = jsHelper.Decrypt(c);
|
|||
|
|
|||
|
context.Response.Write(_modPass(userName, oldpasswd, newpasswd));
|
|||
|
context.Response.End(); ;
|
|||
|
}
|
|||
|
if (context.Request["action"] == "ZC")
|
|||
|
{
|
|||
|
a = context.Request["userAccount"] + "";
|
|||
|
b = context.Request["userName"] + "";
|
|||
|
string c = context.Request["passwd"] + "";
|
|||
|
string d = context.Request["phoneNo"] + "";
|
|||
|
string userAccount = jsHelper.Decrypt(a);
|
|||
|
userName = jsHelper.Decrypt(b);
|
|||
|
string passwd = jsHelper.Decrypt(c);
|
|||
|
string phoneNo = jsHelper.Decrypt(d);
|
|||
|
|
|||
|
|
|||
|
context.Response.Write(_ZC(userAccount, userName, passwd, phoneNo));
|
|||
|
context.Response.End(); ;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private string _ZC(string userAccount, string userName, string passwd, string phoneNo)
|
|||
|
{
|
|||
|
|
|||
|
string json = "";
|
|||
|
|
|||
|
|
|||
|
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + userName + "' or user_account='" + userAccount + "' or phoneNo='" + phoneNo + "'");
|
|||
|
if (dtUser.Rows.Count == 0)
|
|||
|
{
|
|||
|
string strSQL = "insert into user (";
|
|||
|
strSQL += "user_account,";
|
|||
|
strSQL += "user_name,";
|
|||
|
strSQL += "pswd,";
|
|||
|
strSQL += "ORG_ID,";
|
|||
|
strSQL += "regDateTime,";
|
|||
|
strSQL += "phoneNo) values(";
|
|||
|
strSQL += "'" + userAccount + "',";
|
|||
|
strSQL += "'" + userName + "',";
|
|||
|
strSQL += "'" + passwd + "',";
|
|||
|
strSQL += "'" + userAccount + "00',";
|
|||
|
strSQL += "'" + DateTime.Now + "',";
|
|||
|
strSQL += "'" + phoneNo + "')";
|
|||
|
int intState = 0;
|
|||
|
intState = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
if (intState >= 0)
|
|||
|
{
|
|||
|
|
|||
|
strSQL = "insert into organization (";
|
|||
|
strSQL += "ORG_ID,";
|
|||
|
strSQL += "ORG_Name,";
|
|||
|
strSQL += "ORG_PARENT_ID,";
|
|||
|
strSQL += "ORG_TYPE) values(";
|
|||
|
strSQL += "'" + userAccount + "00',";
|
|||
|
strSQL += "'" + userName + "00',";
|
|||
|
strSQL += "'" + "MS00" + "',";
|
|||
|
strSQL += "'" + "公司" + "')";
|
|||
|
intState = 0;
|
|||
|
intState = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
|
|||
|
json = "OK";
|
|||
|
}
|
|||
|
|
|||
|
else
|
|||
|
{
|
|||
|
json = "注册失败";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "账户、电话号码或姓名已被注册,请重新输入!";
|
|||
|
}
|
|||
|
return json;
|
|||
|
}
|
|||
|
|
|||
|
private string _modPass(string userName, string oldpasswd, string newpasswd)
|
|||
|
{
|
|||
|
|
|||
|
string json = ""; ;
|
|||
|
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'");
|
|||
|
if (dtUser.Rows.Count > 0)
|
|||
|
{
|
|||
|
if (dtUser.Rows[0]["pswd"].ToString() == oldpasswd)
|
|||
|
{
|
|||
|
string strSQL = "update user set pswd='" + newpasswd + "' where user_name='" + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'";
|
|||
|
int intState = 0;
|
|||
|
intState = MySQLHelper.ExecuteNonQuery(strSQL);
|
|||
|
if (intState >= 0)
|
|||
|
{
|
|||
|
json = "ok";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "用户名或密码有误,请仔细想想....";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
json = "没有这个用户!";
|
|||
|
}
|
|||
|
return json;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public bool IsReusable
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|