调整登录指令

dev
nxiaoxiao 1 year ago
parent f45f4c0032
commit 4222096a7d

@ -19,12 +19,13 @@ namespace OMS.NET.Instructs
return Task.Run(() =>
{
if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查
try
{
string email = Data.GetProperty("email").GetString();
string password = Data.GetProperty("password").GetString();
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
GlobalArea.Log.Warn("登录信息不能为空!");
return;
throw new Exception("登录信息不能为空");
}
//能够获取到则说明客户端有发送数据过来
Instruct res1 = new()
@ -34,15 +35,13 @@ namespace OMS.NET.Instructs
Data = false
};//默认为false
//Console.WriteLine($"已获取到{email}:{password},解密测试{GlobalArea.DecryptFromBase64String(password)}");
AccountData? accountData = AccountData.Get(email);
AccountData accountData = AccountData.Get(email) ?? throw new Exception($"数据库中不包含用户{email}");
GlobalArea.AddLoginAccountData(accountData);
if (accountData != null)
{
ResponseOrBroadcastInstructs.Add(res1);
//只能原文比较,密文每次都不一样,涉及随机性填充
if (accountData.Password == GlobalArea.DecryptFromBase64String(password))
{
res1.Data = true;//登录成功则修改为true
ResponseOrBroadcastInstructs.Add(res1);
GlobalArea.Log.Info($"{accountData.UserEmail}:登录成功");
GlobalArea.Login(wsid, accountData.UserEmail);
GlobalArea.Log.Info($"当前登录用户数量: {GlobalArea.LoginUserCount}");
@ -60,10 +59,11 @@ namespace OMS.NET.Instructs
IsBroadcast = true
});
}
else
{
ResponseOrBroadcastInstructs.Add(res1);
}
catch (Exception ex)
{
GlobalArea.Log.Warn($"处理{Type}广播指令出错:" + ex.Message);
}
});
}

Loading…
Cancel
Save