修改登录模块~支持多用户登录
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
81
NX.ERP.U8/XmlHelper.cs
Normal 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
43
NX.ERP.U8/ufsoft.cs
Normal 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; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace NX.ERP.WebAPi
|
||||
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
|
||||
{
|
||||
filters.Add(new HandleErrorAttribute());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
30
NX.ERP.WebAPi/Controllers/System/SystemController.cs
Normal file
30
NX.ERP.WebAPi/Controllers/System/SystemController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using NX.ERP.WebAPi.models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
namespace NX.ERP.WebAPi.Controllers.System
|
||||
{
|
||||
|
||||
public class SystemController:ApiController
|
||||
{
|
||||
[HttpPost]
|
||||
[Route("api/System/Login")]
|
||||
public string Login(LoginEntity loginEntity)
|
||||
{
|
||||
var AccID = ConfigurationManager.AppSettings["AccId"];
|
||||
//NX.ERP.U8.U8LoginContext.Instance.PassWord = System.Configuration.ConfigurationManager.AppSettings["Password"];
|
||||
|
||||
//NX.ERP.U8.U8LoginContext.Instance.UserId = System.Configuration.ConfigurationManager.AppSettings["UserId"];
|
||||
|
||||
var Server =ConfigurationManager.AppSettings["Server"];
|
||||
var _login = new NX.ERP.U8.U8LoginContext(Server, AccID);
|
||||
_login.Login(loginEntity.UserId, loginEntity.Password);
|
||||
return _login.loginId;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,12 @@
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Owin, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Swashbuckle.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd1bb07a5ac7c7bc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Swashbuckle.Core.5.6.0\lib\net40\Swashbuckle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -168,13 +174,16 @@
|
||||
<Compile Include="Controllers\Store\SaleStoreOutController.cs" />
|
||||
<Compile Include="Controllers\Store\StockController.cs" />
|
||||
<Compile Include="Controllers\Store\StoreController.cs" />
|
||||
<Compile Include="Controllers\System\SystemController.cs" />
|
||||
<Compile Include="Filters\ApiResultAttribute.cs" />
|
||||
<Compile Include="Filters\ExceptionFilter.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="models\LoginEntity.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ResultModel.cs" />
|
||||
<Compile Include="Startup.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="favicon.ico" />
|
||||
|
||||
18
NX.ERP.WebAPi/Startup.cs
Normal file
18
NX.ERP.WebAPi/Startup.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.Owin;
|
||||
using Owin;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[assembly: OwinStartup(typeof(NX.ERP.WebAPi.Startup))]
|
||||
|
||||
namespace NX.ERP.WebAPi
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void Configuration(IAppBuilder app)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@
|
||||
-->
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="server" value="10.0.0.12"/>
|
||||
<add key="AccId" value="u8-2@001"/>
|
||||
<add key="UserId" value="wx997"/>
|
||||
<add key="Password" value="1"/>
|
||||
<add key="EaiPort" value="80"/>
|
||||
<add key="server" value="10.0.0.12" />
|
||||
<add key="AccId" value="u8-2@001" />
|
||||
<add key="UserId" value="wx997" />
|
||||
<add key="Password" value="1" />
|
||||
<add key="EaiPort" value="80" />
|
||||
<add key="EaiPath" value="U8EAI/import.asp" />
|
||||
<add key="webpages:Version" value="3.0.0.0" />
|
||||
<add key="webpages:Enabled" value="false" />
|
||||
|
||||
16
NX.ERP.WebAPi/models/LoginEntity.cs
Normal file
16
NX.ERP.WebAPi/models/LoginEntity.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace NX.ERP.WebAPi.models
|
||||
{
|
||||
public class LoginEntity
|
||||
{
|
||||
private string userId;
|
||||
private string password;
|
||||
|
||||
public string UserId { get => userId; set => userId = value; }
|
||||
public string Password { get => password; set => password = value; }
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,11 @@
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages.zh-Hans" version="3.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="4.0.1" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="Modernizr" version="2.8.3" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net45" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
<package id="Swashbuckle" version="5.6.0" targetFramework="net45" />
|
||||
<package id="Swashbuckle.Core" version="5.6.0" targetFramework="net45" />
|
||||
<package id="WebActivatorEx" version="2.0" targetFramework="net45" />
|
||||
|
||||
Reference in New Issue
Block a user