new feature
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
namespace SimApi.Communications;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SimApi.Communications;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 登录信息中间件
|
/// 登录信息中间件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record SimApiLoginItem(string Id, string[] Type);
|
public record SimApiLoginItem(string Id, string[] Type,Dictionary<string,string> Meta = null);
|
||||||
@@ -51,4 +51,10 @@ public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
|
|||||||
auth.Logout(token!);
|
auth.Logout(token!);
|
||||||
return new SimApiBaseResponse();
|
return new SimApiBaseResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("/logined"),SimApiAuth]
|
||||||
|
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
|
||||||
|
{
|
||||||
|
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+23
-4
@@ -1,5 +1,6 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using SimApi.Communications;
|
using SimApi.Communications;
|
||||||
@@ -16,11 +17,12 @@ public class SimApiAuth(IDistributedCache cache)
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
|
/// <param name="meta"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Login(string id, string type = "user", string token = null)
|
public string Login(string id, Dictionary<string, string>? meta = null, string type = "user", string? token = null)
|
||||||
{
|
{
|
||||||
return Login(id, new[] { type }, token);
|
return Login(id, meta, new[] { type }, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,16 +30,33 @@ public class SimApiAuth(IDistributedCache cache)
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
|
/// <param name="meta"></param>
|
||||||
/// <param name="uuid"></param>
|
/// <param name="uuid"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Login(string id, string[] type, string uuid = null)
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
|
public string Login(string id, Dictionary<string, string>? meta, string[] type, string? uuid = null)
|
||||||
{
|
{
|
||||||
uuid ??= Guid.NewGuid().ToString();
|
uuid ??= Guid.NewGuid().ToString();
|
||||||
var loginItem = new SimApiLoginItem(id, type);
|
var loginItem = new SimApiLoginItem(id, type, meta);
|
||||||
cache.SetString(uuid, JsonSerializer.Serialize(loginItem));
|
cache.SetString(uuid, JsonSerializer.Serialize(loginItem));
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置登录的Meta信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <param name="meta"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SetMeta(string token, Dictionary<string, string> meta)
|
||||||
|
{
|
||||||
|
var login = GetLogin(token);
|
||||||
|
if (login == null) { return false; }
|
||||||
|
var newLogin = new SimApiLoginItem(login.Id, login.Type, login.Meta);
|
||||||
|
cache.SetString(token,JsonSerializer.Serialize(newLogin));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取登陆信息
|
/// 获取登陆信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class SimApiStorage
|
|||||||
|
|
||||||
private string ServeUrl { get; }
|
private string ServeUrl { get; }
|
||||||
|
|
||||||
private string Bucket { get; }
|
public string Bucket { get; }
|
||||||
|
|
||||||
private IHttpContextAccessor HttpContextAccessor { get; }
|
private IHttpContextAccessor HttpContextAccessor { get; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user