using System.ComponentModel; using System.ComponentModel.DataAnnotations; using Tiku.Application.Auth; namespace Tiku.Api.Contracts; public sealed class PasswordLoginDto { [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 { [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; } public sealed class OAuthCodeDto { [Required] [Description("租户 ID。")] public Guid TenantId { get; set; } [Required] [StringLength(512)] [Description("OAuth 平台返回的一次性授权 code。")] public string Code { get; set; } = string.Empty; [Description("客户端可提供的公开用户资料,不允许包含 token/secret。当前后端先保留模板字段,后续按业务需要逐步使用。")] public Dictionary? Profile { get; set; } [StringLength(20)] [Description("微信用户资料语言,例如 zh_CN。当前微信小程序登录不会使用该字段。")] public string? Lang { get; set; } } public sealed class RefreshSessionDto { [Required] [StringLength(2048)] [Description("refresh token。服务端只存储哈希,明文只返回给客户端一次。")] public string RefreshToken { get; set; } = string.Empty; } public sealed class AuthenticatedUserDto { 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!; 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 }; } }