186 lines
6.1 KiB
C#
186 lines
6.1 KiB
C#
namespace FineUIPro.Web
|
|
{
|
|
using BLL;
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web.Services;
|
|
|
|
public partial class Login : PageBase
|
|
{
|
|
|
|
#region
|
|
/// <summary>
|
|
/// 是否本部
|
|
/// </summary>
|
|
public string IsOffice
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["IsOffice"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["IsOffice"] = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 菜单类型
|
|
/// </summary>
|
|
public string MenuType
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["MenuType"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["MenuType"] = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 项目ID
|
|
/// </summary>
|
|
public string ProjectId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["ProjectId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["ProjectId"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 页面加载
|
|
/// <summary>
|
|
/// 页面加载
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
// BOSHENGMonitorService.AddData(null,null);
|
|
string userdata = Request.Params["basedata"];
|
|
if (!string.IsNullOrEmpty(userdata))
|
|
{
|
|
try
|
|
{
|
|
string result = RSADecrypt(Const.OAPrivateKey_CWCEC, userdata); //经过RSA解密后获得的域登录名+时间戳
|
|
if (!string.IsNullOrEmpty(result))
|
|
{
|
|
var value = Funs.GetStrListByStr(result, '&');
|
|
if (value.Count > 1)
|
|
{
|
|
var userValues = Funs.GetStrListByStr(value[0], '=');
|
|
var timespan = Funs.GetStrListByStr(value[1], '=');
|
|
if (userValues.Count > 1 && timespan.Count > 1 && timespan[1] != null)
|
|
{
|
|
TimeSpan ts = DateTime.Now- new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
//DateTime time = Funs.IntToDateTime(Convert.ToInt64(timespan[1]));
|
|
//if (DateTime.Now < time.AddSeconds(10)) //时间间隔小于10秒
|
|
if (Convert.ToInt64(ts.TotalMilliseconds) - Convert.ToInt64(timespan[1]) < 600000)
|
|
{
|
|
if (LoginService.UserLogOn_OA(userValues[1], true, this.Page))
|
|
{
|
|
string url = getUrl();
|
|
Response.Redirect(url);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("时间戳过期!", MessageBoxIcon.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//ErrLogInfo.WriteLog("OA单点登陆", ex);
|
|
//Alert.ShowInParent(ex.Message, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
[WebMethod]
|
|
public static string LoginPost(string user, string pwd)
|
|
{
|
|
return new Login().btnLogin_Click(user, pwd);
|
|
}
|
|
|
|
private string btnLogin_Click(string user, string pwd)
|
|
{
|
|
string url = "";
|
|
try
|
|
{
|
|
if (LoginService.UserLogOn(user, pwd, true, this.Page))
|
|
{
|
|
url = getUrl();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrLogInfo.WriteLog("登陆错误:" + ex.Message);
|
|
}
|
|
|
|
return url;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取跳转页面
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string getUrl()
|
|
{
|
|
string url = "";
|
|
this.CurrUser.RoleType = RoleService.GetRoleTypeByRoleId(this.CurrUser.RoleId);
|
|
if (!this.CurrUser.LastIsOffice.HasValue)
|
|
{
|
|
this.CurrUser.LastIsOffice = this.CurrUser.IsOffice;
|
|
}
|
|
if (this.CurrUser.LastIsOffice == true)
|
|
{
|
|
this.CurrUser.LoginProjectId = null;
|
|
////本部菜单
|
|
url = "index.aspx";
|
|
}
|
|
else
|
|
{
|
|
this.CurrUser.LoginProjectId = this.CurrUser.LastProjectId;
|
|
//// 项目菜单
|
|
url = "indexProject.aspx?projectId=" + this.CurrUser.LastProjectId;
|
|
}
|
|
|
|
LogService.AddSys_Log(this.CurrUser, this.CurrUser.UserName, this.CurrUser.UserId, Const.UserMenuId, Const.BtnLogin);
|
|
|
|
return url;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 用私钥对数据进行RSA解密
|
|
/// </summary>
|
|
/// <param name="privatekey"></param>
|
|
/// <param name="content"></param>
|
|
/// <returns></returns>
|
|
public static string RSADecrypt(string privatekey, string content)
|
|
{
|
|
|
|
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
|
byte[] cipherbytes;
|
|
rsa.FromXmlString(privatekey);
|
|
//对参数content进行两次base64解密
|
|
cipherbytes = rsa.Decrypt(Convert.FromBase64String(Encoding.UTF8.GetString(Convert.FromBase64String(content))), false);
|
|
return Encoding.UTF8.GetString(cipherbytes);
|
|
}
|
|
}
|
|
}
|