23 lines
871 B
C#
23 lines
871 B
C#
using MAX.Core.DependencyInjection;
|
|
using Store.Management.Api;
|
|
using Store.Management.Api.Authentication;
|
|
|
|
namespace Store.Management.Framework.Services;
|
|
|
|
/// <summary>用户登录服务,复用应用 API 客户端的认证会话。</summary>
|
|
public interface ILoginService
|
|
{
|
|
/// <summary>提交登录;passwordHash 为 UTF-8 密码的 32 位大写 MD5。</summary>
|
|
Task LoginAsync(string userName, string passwordHash, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
internal sealed class LoginService(StoreApiClient apiClient) : ILoginService, ISingletonDependency
|
|
{
|
|
public Task LoginAsync(string userName, string passwordHash, CancellationToken cancellationToken = default)
|
|
=> apiClient.Auth.LoginAsync(new LoginRequest
|
|
{
|
|
UserName = userName.Trim(),
|
|
Password = passwordHash
|
|
}, cancellationToken);
|
|
}
|