XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.ServerInteractive

[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Net;
using System.Text.Json;
using XFEExtension.NetCore.ServerInteractive.Attributes;
using XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;
using XFEExtension.NetCore.StringExtension;

namespace XFEExtension.NetCore.ServerInteractive.Utilities.Server.Services.CoreService;

/// <summary>不透明会话令牌校验服务。</summary>
public partial class UserReloginService<T> : ServerCoreUserLoginServiceBase<T> where T : class
{
    [EntryPoint("user/relogin")]
    public async Task Relogin()
    {
        Console.Write("校验登录请求:");
        var session = Json?["session"]?.GetString();
        var deviceInfo = Json?["deviceInfo"]?.GetString();
        if (session.IsNullOrWhiteSpace()) throw Error("Session值不能为空");
        if (deviceInfo.IsNullOrWhiteSpace()) throw Error("电脑信息不能为空");

        var result = UserHelper.GetUser(session, deviceInfo, ReturnArgs.ClientIP,
            GetEncryptedUserLoginModelFunction(), GetUserFunction(), out var user);
        if (result != Models.UserModels.UserOperateResult.Success || user is null)
            throw Error("Session值不正确或已过期", HttpStatusCode.Forbidden);
        if (!user.Enable) throw Error("用户已禁用", HttpStatusCode.Forbidden);

        Console.Write($"session={SessionTokenHelper.Hash(session)[..10]}");
        await ReturnArgs.CloseJson(LoginResultConvertFunction(user), JsonSerializerOptions);
    }
}