using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Tiku.Application.Auth;
namespace Tiku.Api.Contracts;
///
/// 手机号密码登录请求。
///
public sealed class PasswordLoginDto
{
///
/// 租户 ID。登录阶段允许客户端指定租户,登录后的业务接口以 JWT/session 解析出的当前租户为准。
///
[Required]
[Description("租户 ID。登录阶段允许客户端指定租户,登录后的业务接口以 JWT/session 解析出的当前租户为准。")]
public Guid TenantId { get; set; }
///
/// 手机号,建议前端提交规范化后的中国大陆手机号。
///
[Required]
[StringLength(32)]
[Description("手机号,建议前端提交规范化后的中国大陆手机号。")]
public string Phone { get; set; } = string.Empty;
///
/// 用户密码。
///
[Required]
[StringLength(128, MinimumLength = 6)]
[Description("用户密码。")]
public string Password { get; set; } = string.Empty;
}
///
/// 短信验证码登录请求。
///
public sealed class SmsLoginDto
{
///
/// 租户 ID。
///
[Required]
[Description("租户 ID。")]
public Guid TenantId { get; set; }
///
/// 中国大陆手机号。
///
[Required]
[StringLength(32)]
[Description("中国大陆手机号。")]
public string Phone { get; set; } = string.Empty;
///
/// 收到的短信验证码。
///
[Required]
[StringLength(12, MinimumLength = 4)]
[Description("收到的短信验证码。")]
public string Code { get; set; } = string.Empty;
}
///
/// OAuth code 登录请求。
///
public sealed class OAuthCodeDto
{
///
/// 租户 ID。
///
[Required]
[Description("租户 ID。")]
public Guid TenantId { get; set; }
///
/// OAuth 平台返回的一次性授权 code。
///
[Required]
[StringLength(512)]
[Description("OAuth 平台返回的一次性授权 code。")]
public string Code { get; set; } = string.Empty;
///
/// 客户端可提供的公开用户资料,不允许包含 token/secret。当前后端先保留模板字段,后续按业务需要逐步使用。
///
[Description("客户端可提供的公开用户资料,不允许包含 token/secret。当前后端先保留模板字段,后续按业务需要逐步使用。")]
public Dictionary? Profile { get; set; }
///
/// 微信用户资料语言,例如 zh_CN。当前微信小程序登录不会使用该字段。
///
[StringLength(20)]
[Description("微信用户资料语言,例如 zh_CN。当前微信小程序登录不会使用该字段。")]
public string? Lang { get; set; }
}
///
/// refresh token 请求。
///
public sealed class RefreshSessionDto
{
///
/// refresh token。服务端只存储哈希,明文只返回给客户端一次。
///
[Required]
[StringLength(2048)]
[Description("refresh token。服务端只存储哈希,明文只返回给客户端一次。")]
public string RefreshToken { get; set; } = string.Empty;
}
///
/// 登录成功后的用户、租户成员和令牌信息。
///
public sealed class AuthenticatedUserDto
{
///
/// 用户 ID。
///
public Guid UserId { get; init; }
///
/// 手机号。
///
public string? Phone { get; init; }
///
/// 邮箱。
///
public string? Email { get; init; }
///
/// 用户显示名称。
///
public string? Name { get; init; }
///
/// 当前登录租户成员摘要。
///
public TenantMembershipSummary Tenant { get; init; } = default!;
///
/// access token 和 refresh token。
///
public AuthTokenPair Tokens { get; init; } = default!;
public static AuthenticatedUserDto FromApplication(AuthenticatedUser user)
{
return new AuthenticatedUserDto
{
UserId = user.UserId,
Phone = user.Phone,
Email = user.Email,
Name = user.Name,
Tenant = user.Tenant,
Tokens = user.Tokens
};
}
}