You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
7.6 KiB
227 lines
7.6 KiB
|
|
using Newtonsoft.Json;
|
|
using OT.COM.ArsenalDB;
|
|
using OT.COM.LogisticsUtil;
|
|
using OT.COM.SignalerMessage;
|
|
using SoldierData;
|
|
using SoldierData.syserp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Newtonsoft.Json.Linq;
|
|
using SoldierDataEntity;
|
|
using System.DirectoryServices;
|
|
using System.Collections;
|
|
using System.Net;
|
|
|
|
namespace CounsellorBL
|
|
{
|
|
public partial class AuthorityService : DBService
|
|
{
|
|
public const string MODE = "mode";
|
|
protected CResponseMessage loginBase(CRequestMessage i_crm, otb_user i_u)
|
|
{
|
|
CResponseMessage crm = null;
|
|
string sMsg = null;
|
|
do
|
|
{
|
|
if (null == i_u)
|
|
{
|
|
sMsg = BaseExceptionWord.ex000001; //請輸入正確的帳號和密碼或該帳號無效
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
// Add row to session
|
|
string sGUID = Guid.NewGuid().ToString();
|
|
otb_session s = new otb_session();
|
|
//s.user_name = i_u.user_name;
|
|
s.create_user_guid = s.modify_user_guid = i_u.guid;
|
|
//s.login_ip = i_crm.ClientIP;
|
|
s.guid = sGUID;
|
|
Command cAddSession = Command.SetupInsertCmd(GetMasterDBTableInfo(typeof(otb_session)), s);
|
|
|
|
|
|
Command cDelSession = Command.SetupDeleteCmd(GetMasterDBTableInfo(typeof(otb_session)),
|
|
new WhereNode(otb_session.CN_MODIFY_DATE, WhereNode.EColumnOperation.EOT_LT, typeof(otb_session), DateTime.Now.AddHours(-1)));
|
|
|
|
if (0 >= this.adbm.RunEditCmds(new List<Command>() { cDelSession, cAddSession }))
|
|
{
|
|
sMsg = BaseExceptionWord.ex000002;//SESSION 新增失敗
|
|
if (true == new Util().GetSettingBoolean("EnableDebug")) //ConfigurationManager.AppSettings <compilation debug="true"...
|
|
{
|
|
//sMsg += string.Format("({0})", cAddSession.LastErrorMsg);
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Get GUID
|
|
//decimal dFidLastInsert = (decimal)cAddSession.LastInsertIdentity;
|
|
//int nFidLastInsert = Convert.ToInt32(dFidLastInsert);
|
|
/*
|
|
otb_session sFethch = new otb_session();
|
|
sFethch.SetDirty(otb_session.CN_F_S_GUID);
|
|
WhereNode wn = new WhereNode(otb_session.CN_F_S_GUID, WhereNode.EColumnOperation.EOT_EQ, sGUID);
|
|
|
|
Command cWhereLastInsert = Command.SetupSelectCmd(GetMasterDBTableInfo(typeof(otb_session)), sFethch, wn);
|
|
QueryDataTable qdr2 = this.adbm.RunQuery(cWhereLastInsert);
|
|
DataTable dt2 = qdr2.DATA;*/
|
|
|
|
crm = new CSuccessResponseMessage("LOGIN SUCCESS", i_crm);
|
|
|
|
|
|
|
|
crm.DATA.Add(BLWording.TOKEN, sGUID);
|
|
}
|
|
while (false);
|
|
|
|
if (null != sMsg)
|
|
{
|
|
crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
|
|
}
|
|
|
|
return crm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Login check
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public CResponseMessage Login(CRequestMessage i_crm)
|
|
{
|
|
// IN
|
|
|
|
CResponseMessage crm = null;
|
|
string sMsg = null;
|
|
|
|
string sEmprolyeeid = i_crm.DATA["user_id"].ToString();
|
|
string sPassword = i_crm.DATA["password"].ToString();
|
|
string sMethod = _fetchString(i_crm, "cmbloginmethod");
|
|
//string sIp = _fetchString(i_crm, "Ip");
|
|
string sIp = GetWebClientIp();
|
|
// 加密
|
|
//sMsg = EncryptMgr.Encrypt(sPassword, out sEnctPassword);
|
|
|
|
do
|
|
{
|
|
QueryJson qj = new QueryJson();
|
|
|
|
List<QueryJsonElement> lqje = new List<QueryJsonElement>();
|
|
|
|
QueryJsonElement qjeA = new QueryJsonElement();
|
|
|
|
qjeA.table = otb_user.TABLENAME;
|
|
qjeA.tablealias = "a";
|
|
|
|
qjeA.wherecols = new WhereNode(otb_user.CN_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(otb_user), sEmprolyeeid) { EQCaseSensitiveSupport = false };
|
|
|
|
qjeA.ordercols = new List<Dictionary<string, string>>() { new Dictionary<string, string>() { { otb_user.CN_CREATE_DATE, "DESC" } } };
|
|
qj.AddBlock(qjeA);
|
|
Command cSelect = null;
|
|
|
|
qj.MakeCommand(GetMasterDBTableInfo(typeof(otb_user)), out cSelect);
|
|
|
|
otb_user uSelectItem = new otb_user();
|
|
//uSelectItem.SetDirty(tb_user.F_N_ID);
|
|
|
|
otb_user u = this.adbm.RunQuerySingleORM<otb_user>(cSelect);
|
|
|
|
if (null == u)
|
|
{
|
|
sMsg = BaseExceptionWord.login001; //請輸入正確的帳號和密碼
|
|
break;
|
|
}
|
|
|
|
|
|
// Expire
|
|
if (u.active_flag != "Y")
|
|
{
|
|
sMsg = BaseExceptionWord.login002; //該帳號無效
|
|
break;
|
|
}
|
|
|
|
crm = loginBase(i_crm, u);
|
|
|
|
if (crm.RESULT == EResponseResult.RR_TRUE)
|
|
{
|
|
|
|
crm.DATA.Add(otb_user.CN_USER_ID, u.user_id);
|
|
crm.DATA.Add(otb_user.CN_USER_NAME, u.user_name);
|
|
crm.DATA.Add(BLWording.ENTITYS, new List<otb_user>() { u }); //這裡放entity登入帳號資料
|
|
}
|
|
|
|
}
|
|
while (false);
|
|
|
|
if (null != sMsg)
|
|
{
|
|
|
|
crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
|
|
}
|
|
|
|
return crm;
|
|
}
|
|
|
|
|
|
#region 获取web客户端ip
|
|
/// <summary>
|
|
/// 获取web客户端ip
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetWebClientIp()
|
|
{
|
|
|
|
string sUserIP = "";
|
|
|
|
try
|
|
{
|
|
if (System.Web.HttpContext.Current == null
|
|
|| System.Web.HttpContext.Current.Request == null
|
|
|| System.Web.HttpContext.Current.Request.ServerVariables == null)
|
|
return "";
|
|
|
|
string CustomerIP = "";
|
|
|
|
//CDN加速后取到的IP simone 090805
|
|
CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
|
|
if (!string.IsNullOrEmpty(CustomerIP))
|
|
{
|
|
return CustomerIP;
|
|
}
|
|
|
|
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
|
|
|
|
|
if (!String.IsNullOrEmpty(CustomerIP))
|
|
return CustomerIP;
|
|
|
|
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
|
|
{
|
|
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
|
if (CustomerIP == null)
|
|
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
|
|
}
|
|
else
|
|
{
|
|
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
|
|
|
|
}
|
|
|
|
if (string.Compare(CustomerIP, "unknown", true) == 0)
|
|
return System.Web.HttpContext.Current.Request.UserHostAddress;
|
|
return CustomerIP;
|
|
}
|
|
catch { }
|
|
|
|
return sUserIP;
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|