316 lines
12 KiB
C#
316 lines
12 KiB
C#
using BLL;
|
||
using BLL.Oauth;
|
||
using Model;
|
||
using System;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Web;
|
||
using System.Web.Security;
|
||
using System.Web.Services;
|
||
using System.Web.UI;
|
||
|
||
namespace FineUIPro.Web
|
||
{
|
||
public partial class Login_ZJ : 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)
|
||
{
|
||
bool IsSSO = false;
|
||
Sys_User user=new Sys_User();
|
||
string message="";
|
||
IOauthService IoauthService;
|
||
|
||
var ThisUnit = CommonService.GetIsThisUnit();
|
||
string token;
|
||
switch (ThisUnit.CollCropCode)
|
||
{
|
||
case "913201001349030968":
|
||
|
||
token = Request.Params["token"];
|
||
if (string.IsNullOrEmpty(token)) return;
|
||
IsSSO = true;
|
||
IoauthService = new OauthService_14HJ();
|
||
user = IoauthService.GetLoginInfo(token, ref message);
|
||
break;
|
||
}
|
||
|
||
if (IsSSO )
|
||
{
|
||
if (message != "")
|
||
{
|
||
Response.Write("<script language=javascript>alert('" + message + "');</script>");
|
||
}
|
||
else
|
||
{
|
||
if (LoginService.UserLogOn(user.Account, true, this.Page))
|
||
{
|
||
string url = "";
|
||
//Funs.SystemUrl = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/cncechsse/";
|
||
BLL.LogService.AddLog(this.CurrUser.UserId, "登录成功!");
|
||
if (this.CurrUser.IsOffice==true) //本部人员跳转到公司级
|
||
{
|
||
url = "index_ZJ.aspx";
|
||
}
|
||
else //非本部人员跳转到项目级
|
||
{
|
||
if (string.IsNullOrEmpty(this.CurrUser.LastProjectId))
|
||
{
|
||
var puser = Funs.DB.Project_ProjectUser.FirstOrDefault(x => x.UserId == this.CurrUser.UserId);
|
||
if (puser != null)
|
||
{
|
||
this.CurrUser.LastProjectId = puser.ProjectId;
|
||
}
|
||
}
|
||
|
||
this.CurrUser.LoginProjectId = this.CurrUser.LastProjectId;
|
||
//// 项目菜单
|
||
url = "indexProject_ZJ.aspx?projectId=" + this.CurrUser.LastProjectId;
|
||
}
|
||
|
||
|
||
HttpContext.Current.Response.Write("<script> top.window.location.href='" + url + "';</script>");
|
||
HttpContext.Current.Response.End();
|
||
// Response.Redirect( url);
|
||
// Server.Execute( url);
|
||
// Response.Write("<script language='javascript'>window.open('" + url + "');</script>");
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
[WebMethod]
|
||
public static string LoginPost(string user, string pwd,string rbSys)
|
||
{
|
||
return new Login_ZJ().btnLogin_Click(user, pwd, rbSys);
|
||
}
|
||
|
||
private string btnLogin_Click(string user, string pwd, string rbSys)
|
||
{
|
||
|
||
string url = "";
|
||
string error = "";
|
||
var sysUser = Funs.DB.Sys_User.FirstOrDefault(x => x.Account == user && x.IsPost == true);
|
||
if (sysUser != null)
|
||
{
|
||
if (sysUser.LockTime.HasValue && sysUser.LockTime.Value > DateTime.Now)
|
||
{
|
||
error = "账号锁定10分钟!";
|
||
}
|
||
else
|
||
{
|
||
if (sysUser.Password.ToUpper() != Funs.EncryptionPassword(pwd).ToUpper())
|
||
{
|
||
if (sysUser.LockTime.HasValue && sysUser.LockTime.Value < DateTime.Now)
|
||
{
|
||
sysUser.ErrorTimes = null;
|
||
sysUser.LockTime = null;
|
||
|
||
UserService.UpdateSysUser(sysUser);
|
||
}
|
||
if (sysUser.ErrorTimes.HasValue && sysUser.ErrorTimes.Value >= 4)
|
||
{
|
||
sysUser.ErrorTimes = sysUser.ErrorTimes.Value + 1;
|
||
sysUser.LockTime = DateTime.Now.AddMinutes(10);
|
||
UserService.UpdateSysUser(sysUser);
|
||
error = "账号锁定10分钟!";
|
||
}
|
||
else if (sysUser.ErrorTimes.HasValue)
|
||
{
|
||
sysUser.ErrorTimes = sysUser.ErrorTimes.Value + 1;
|
||
UserService.UpdateSysUser(sysUser);
|
||
// error = "密码错误" + sysUser.ErrorTimes + "次,超过5次将锁定10分钟!";
|
||
error = "用户名或密码错误,请重新输入";
|
||
|
||
}
|
||
else
|
||
{
|
||
sysUser.ErrorTimes = 1;
|
||
UserService.UpdateSysUser(sysUser);
|
||
error = "用户名或密码错误,请重新输入";
|
||
// error = "密码错误" + sysUser.ErrorTimes + "次,超过5次将锁定10分钟!";
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
sysUser.ErrorTimes = null;
|
||
sysUser.LockTime = null;
|
||
|
||
UserService.UpdateSysUser(sysUser);
|
||
|
||
string accValue = HttpUtility.UrlEncode(user);
|
||
FormsAuthentication.SetAuthCookie(accValue, false);
|
||
Page.Session[SessionName.CurrUser] = sysUser;
|
||
// var user = x.First();
|
||
|
||
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_ZJ.aspx";
|
||
//}
|
||
//else
|
||
{
|
||
|
||
if (string.IsNullOrEmpty(this.CurrUser.LastProjectId))
|
||
{
|
||
var puser = Funs.DB.Project_ProjectUser.FirstOrDefault(x => x.UserId == this.CurrUser.UserId);
|
||
if (puser != null)
|
||
{
|
||
this.CurrUser.LastProjectId = puser.ProjectId;
|
||
}
|
||
}
|
||
|
||
this.CurrUser.LoginProjectId = this.CurrUser.LastProjectId;
|
||
//// 项目菜单
|
||
url = "indexProject_ZJ.aspx?projectId=" + this.CurrUser.LastProjectId;
|
||
}
|
||
|
||
LogService.AddSys_Log(this.CurrUser, this.CurrUser.UserName, this.CurrUser.UserId, Const.UserMenuId, Const.BtnLogin);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
error = "用户名或密码错误,请重新输入!";
|
||
}
|
||
|
||
//if (LoginService.UserLogOn(user, pwd, true, this.Page))
|
||
//{
|
||
|
||
//}
|
||
if (rbSys == "工程")
|
||
{
|
||
this.SysType = "GONGCHENG";
|
||
}
|
||
else if (rbSys == "公司/分公司")
|
||
{
|
||
url = "index_ZJ.aspx";
|
||
this.SysType = "GONGCHENG";
|
||
}
|
||
else if (rbSys == "实业")
|
||
{
|
||
this.SysType = "SHIYE";
|
||
|
||
url = "indexProjectShiYe.aspx";
|
||
//Dictionary<string, string> parameters = new Dictionary<string, string>();
|
||
//parameters.Add("user", user);
|
||
//parameters.Add("pwd", pwd);
|
||
//parameters.Add("rbSys", rbSys);
|
||
//string res = CommonService.sendHttp("https://lygcgs.com.cn/subqhse/Login.aspx/LoginPost", JsonConvert.SerializeObject(parameters), "post");
|
||
//var resDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(res);
|
||
//url = "https://lygcgs.com.cn/subqhse/" + resDic["d"];
|
||
|
||
}
|
||
if (string.IsNullOrEmpty(error))
|
||
{
|
||
return url;
|
||
}
|
||
else
|
||
{
|
||
return error;
|
||
}
|
||
}
|
||
private string ConvertToHex(byte[] binary)
|
||
{
|
||
return binary.Aggregate(
|
||
new StringBuilder(),
|
||
(acc, c) => acc.AppendFormat("{0:x2}", c),
|
||
acc => acc.ToString());
|
||
}
|
||
|
||
|
||
[WebMethod]
|
||
public static string ResetPost(string accout, string name, string idcard)
|
||
{
|
||
|
||
Model.Sys_User sysUser = (from y in Funs.DB.Sys_User
|
||
where y.Account == accout && y.IsPost == true
|
||
select y).FirstOrDefault();
|
||
if (sysUser ==null)
|
||
{
|
||
return "用户名或密码错误,请重新输入";
|
||
}
|
||
else if (string.IsNullOrEmpty(sysUser.IdentityCard))
|
||
{
|
||
return "用户名或密码错误,请重新输入";
|
||
}
|
||
else if(name != sysUser.UserName)
|
||
{
|
||
return "用户名或密码错误,请重新输入";
|
||
}
|
||
else if (idcard != sysUser.IdentityCard)
|
||
{
|
||
return "用户名或密码错误,请重新输入";
|
||
}
|
||
sysUser.RawPassword = "cncec." + idcard.Substring(idcard.Length - 4, 4);
|
||
sysUser.Password = Funs.EncryptionPassword(sysUser.RawPassword);
|
||
Funs.DB.SubmitChanges();
|
||
return "重置成功,默认密码是 cncec+'.'+身份证号码后四位,请登录";
|
||
}
|
||
}
|
||
}
|