修改登录模块~支持多用户登录

This commit is contained in:
gongxh
2021-04-26 11:29:45 +08:00
parent d5e2ee0414
commit 3bf3bdb07c
11 changed files with 297 additions and 28 deletions

View File

@@ -62,8 +62,10 @@
<Compile Include="U8LoginContext.cs" />
<Compile Include="Base\UnitDAL.cs" />
<Compile Include="Base\WarehouseDAL.cs" />
<Compile Include="ufsoft.cs" />
<Compile Include="VoucherParameter.cs" />
<Compile Include="VT.cs" />
<Compile Include="XmlHelper.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -86,6 +88,7 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.XML" />
<Reference Include="UFIDA.U8.MomServiceCommon">
<HintPath>E:\U8SOFT\UFMOM\U8APIFramework\UFIDA.U8.MomServiceCommon.dll</HintPath>
</Reference>

View File

@@ -10,10 +10,12 @@ namespace NX.ERP.U8
{
public class U8LoginContext : IDisposable
{
#region 单例
private static readonly object locker = new object();
private static U8LoginContext _u8LoginContext;
private string EaiPort = System.Configuration.ConfigurationManager.AppSettings["EaiPort"];
private string EaiPath = System.Configuration.ConfigurationManager.AppSettings["EaiPath"];
/// <summary>
/// 默认实例
/// </summary>
public static U8LoginContext Instance
{
get
@@ -25,6 +27,7 @@ namespace NX.ERP.U8
if (_u8LoginContext == null)
{
_u8LoginContext = new U8LoginContext();
}
}
@@ -35,6 +38,10 @@ namespace NX.ERP.U8
private UFSoft.U8.Framework.Login.UI.clsLogin uiLogin;
private clsLogin _clslogin;
#endregion
private string EaiPort = System.Configuration.ConfigurationManager.AppSettings["EaiPort"];
private string EaiPath = System.Configuration.ConfigurationManager.AppSettings["EaiPath"];
public string cAcc_id
{
@@ -44,9 +51,29 @@ namespace NX.ERP.U8
}
}
/// <summary>
///
/// </summary>
public U8LoginContext()
{
}
/// <summary>
///
/// </summary>
/// <param name="Server"></param>
/// <param name="Accid"></param>
public U8LoginContext(string Server, string Accid)
{
this._server = Server;
this._accid = Accid;
}
public U8LoginContext(string userid, string password, string server, string accid) : this(server, accid)
{
this._password = password;
this._userId = userid;
}
private static readonly object locker1 = new object();
public clsLogin ClsLogin
@@ -256,35 +283,18 @@ namespace NX.ERP.U8
string.IsNullOrEmpty(this._password) ||
string.IsNullOrEmpty(this._server) ||
string.IsNullOrEmpty(this._accid);
}
}
public void Login()
public void Login(string userId, string password)
{
if (NeedUiLogin)
if (!UiLogin.login("DP", userId, password, this._server, DateTime.Today.ToString("yyyy-MM-dd"), this._accid, Serial))
{
if (!UiLogin.login("DP"))
{
throw new Exception(UiLogin.ErrDescript);
}
throw new Exception(UiLogin.ErrDescript);
}
else
{
if (!UiLogin.login("DP", this._userId, this._password, this._server, DateTime.Today.ToString("yyyy-MM-dd"), this._accid, Serial))
{
throw new Exception(UiLogin.ErrDescript);
}
}
if (UiLogin.SubLogin("ST") == null)
{
@@ -299,6 +309,62 @@ namespace NX.ERP.U8
}
/// <summary>
/// 登录ID 唯一凭据
/// </summary>
public string loginId
{
get
{
return this.UserToken == null ? "" : this.UserToken.UserTokenData.SignedToken.Id;
}
}
public ufsoft UserToken
{
get
{
if (this._clslogin == null)
{
return null;
}
if (this._clslogin.userToken=="")
{
return null;
}
return XmlHelper.XmlDeserialize<ufsoft>(this._clslogin.userToken, Encoding.UTF8);
}
}
public void Login()
{
if (NeedUiLogin)
{
if (!UiLogin.login("DP"))
{
throw new Exception(UiLogin.ErrDescript);
}
}
else
{
if (!UiLogin.login("DP", this._userId, this._password, this._server, DateTime.Today.ToString("yyyy-MM-dd"), this._accid, Serial))
{
throw new Exception(UiLogin.ErrDescript);
}
}
if (UiLogin.SubLogin("ST") == null)
{
throw new Exception(UiLogin.ErrDescript);
}
this._clslogin = new clsLoginClass();
if (!_clslogin.ConstructLogin(UiLogin.userToken))
{
throw new Exception(_clslogin.ShareString);
}
_clslogin.set_TaskId(UiLogin.GetTaskID("ST"));
}

81
NX.ERP.U8/XmlHelper.cs Normal file
View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace NX.ERP.U8
{
/// <summary>
/// XML转化对象
/// </summary>
public static class XmlHelper
{
private static void XmlSerializeInternal(Stream stream, object o, Encoding encoding)
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = new XmlSerializer(o.GetType());
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineChars = "\r\n";
settings.Encoding = encoding;
settings.IndentChars = " ";
//settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
using (XmlWriter writer = XmlWriter.Create(stream, settings))
{
serializer.Serialize(writer, o, ns);
writer.Close();
}
}
/// <summary>
/// 将一个对象序列化为XML字符串
/// </summary>
/// <param name="o">要序列化的对象</param>
/// <param name="encoding">编码方式</param>
/// <returns>序列化产生的XML字符串</returns>
public static string XmlSerialize(object o, Encoding encoding)
{
using (MemoryStream stream = new MemoryStream())
{
XmlSerializeInternal(stream, o, encoding);
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream, encoding))
{
return reader.ReadToEnd();
}
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static T XmlDeserialize<T>(string s, Encoding encoding)
{
if (string.IsNullOrEmpty(s))
throw new ArgumentNullException("s");
if (encoding == null)
throw new ArgumentNullException("encoding");
XmlSerializer mySerializer = new XmlSerializer(typeof(T));
s = s.Replace(" ", " ");
using (MemoryStream ms = new MemoryStream(encoding.GetBytes(s)))
{
using (StreamReader sr = new StreamReader(ms, encoding))
{
return (T)mySerializer.Deserialize(sr);
}
}
}
}
}

43
NX.ERP.U8/ufsoft.cs Normal file
View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NX.ERP.U8
{
public class ufsoft
{
[System.Xml.Serialization.XmlElement(Type = typeof(UserTokenData), ElementName = "data")]
public UserTokenData UserTokenData { get; set; }
[System.Xml.Serialization.XmlElement(Type = typeof(AppServer), ElementName = "AppServerName")]
public AppServer AppServerName { get; set; }
}
public class AppServer
{
[System.Xml.Serialization.XmlAttribute]
public string Name { get; set; }
}
public class UserTokenData
{
[System.Xml.Serialization.XmlElement(Type = typeof(SignedToken), ElementName = "SignedToken")]
public SignedToken SignedToken { get; set; }
}
public class SignedToken
{
[System.Xml.Serialization.XmlAttribute(AttributeName="id")]
public string Id { get; set; }
[System.Xml.Serialization.XmlAttribute(AttributeName = "value")]
public string Value { get; set; }
}
}