XFEExtension.NetCore.ServerInteractive
[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig
关注
0
Fork
0
Star
0
using System.Text.Json;
using XFEExtension.NetCore.ServerInteractive.Attributes;
using XFEExtension.NetCore.ServerInteractive.Models.UserModels;
using XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;
namespace XFEExtension.NetCore.ServerInteractive.Utilities.Server.Services.CoreService;
/// <summary>撤销当前会话或当前用户的全部会话。</summary>
public partial class UserLogoutService : ServerCoreUserServiceBase
{
/// <summary>撤销当前不透明会话令牌。</summary>
[EntryPoint("user/logout")]
public async Task Logout()
{
var user = User;
EncryptedUserLoginModel? session;
lock (SessionStoreSynchronization.Gate)
{
session = GetEncryptedUserLoginModelFunction().FirstOrDefault(candidate =>
candidate.UserLoginModel.Uid == user.Id && SessionTokenHelper.Matches(Session, candidate.TokenHash));
if (session is not null) RemoveEncryptedUserLoginModelFunction(session);
}
await ReturnArgs.CloseJson(new { revoked = session is not null }, JsonSerializerOptions);
}
/// <summary>撤销当前用户在所有设备上的会话。</summary>
[EntryPoint("user/logout/all")]
public async Task LogoutAll()
{
var user = User;
var revoked = 0;
lock (SessionStoreSynchronization.Gate)
{
foreach (var session in GetEncryptedUserLoginModelFunction().Where(candidate =>
candidate.UserLoginModel.Uid == user.Id).ToArray())
{
RemoveEncryptedUserLoginModelFunction(session);
revoked++;
}
}
await ReturnArgs.CloseJson(new { revoked }, JsonSerializerOptions);
}
}
using System.Text.Json;
using XFEExtension.NetCore.ServerInteractive.Attributes;
using XFEExtension.NetCore.ServerInteractive.Models.UserModels;
using XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;
namespace XFEExtension.NetCore.ServerInteractive.Utilities.Server.Services.CoreService;
/// <summary>撤销当前会话或当前用户的全部会话。</summary>
public partial class UserLogoutService : ServerCoreUserServiceBase
{
/// <summary>撤销当前不透明会话令牌。</summary>
[EntryPoint("user/logout")]
public async Task Logout()
{
var user = User;
EncryptedUserLoginModel? session;
lock (SessionStoreSynchronization.Gate)
{
session = GetEncryptedUserLoginModelFunction().FirstOrDefault(candidate =>
candidate.UserLoginModel.Uid == user.Id && SessionTokenHelper.Matches(Session, candidate.TokenHash));
if (session is not null) RemoveEncryptedUserLoginModelFunction(session);
}
await ReturnArgs.CloseJson(new { revoked = session is not null }, JsonSerializerOptions);
}
/// <summary>撤销当前用户在所有设备上的会话。</summary>
[EntryPoint("user/logout/all")]
public async Task LogoutAll()
{
var user = User;
var revoked = 0;
lock (SessionStoreSynchronization.Gate)
{
foreach (var session in GetEncryptedUserLoginModelFunction().Where(candidate =>
candidate.UserLoginModel.Uid == user.Id).ToArray())
{
RemoveEncryptedUserLoginModelFunction(session);
revoked++;
}
}
await ReturnArgs.CloseJson(new { revoked }, JsonSerializerOptions);
}
}