mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: Refactor authentication and token management
- Updated EchoHubConnection to use ApiClient for token retrieval. - Introduced ValidationConstants for common validation patterns and limits. - Enhanced AuthDtos with refresh token support and expiration details. - Added new ChatDtos for channel creation and topic updates. - Created CommonDtos for error and paginated responses. - Implemented RefreshToken model for managing refresh tokens. - Modified JwtTokenService to generate and hash refresh tokens. - Updated AuthController to handle registration, login, token refresh, and logout with improved error handling. - Enhanced ChannelsController with channel creation, topic updates, and pagination for channel retrieval. - Added FilesController for file management with rate limiting. - Improved UsersController for profile updates and avatar uploads with validation. - Integrated rate limiting across controllers to manage request load. - Introduced FileValidationHelper for validating uploaded image files. - Updated database context to include RefreshToken and enforce unique constraints. - Enhanced ChatHub for improved channel and message handling with validation. - Updated Program.cs to configure rate limiting and CORS policies.
This commit is contained in:
@@ -9,6 +9,7 @@ public class EchoHubDbContext(DbContextOptions<EchoHubDbContext> options) : DbCo
|
||||
public DbSet<User> Users => Set<User>();
|
||||
public DbSet<Channel> Channels => Set<Channel>();
|
||||
public DbSet<Message> Messages => Set<Message>();
|
||||
public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@@ -36,7 +37,7 @@ public class EchoHubDbContext(DbContextOptions<EchoHubDbContext> options) : DbCo
|
||||
modelBuilder.Entity<Channel>(entity =>
|
||||
{
|
||||
entity.HasKey(c => c.Id);
|
||||
entity.HasIndex(c => c.Name);
|
||||
entity.HasIndex(c => c.Name).IsUnique();
|
||||
entity.Property(c => c.Name).IsRequired().HasMaxLength(100);
|
||||
entity.Property(c => c.Topic).HasMaxLength(500);
|
||||
|
||||
@@ -56,6 +57,19 @@ public class EchoHubDbContext(DbContextOptions<EchoHubDbContext> options) : DbCo
|
||||
entity.Property(m => m.AttachmentFileName).HasMaxLength(255);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RefreshToken>(entity =>
|
||||
{
|
||||
entity.HasKey(r => r.Id);
|
||||
entity.HasIndex(r => r.TokenHash);
|
||||
entity.HasIndex(r => r.UserId);
|
||||
entity.Property(r => r.TokenHash).IsRequired().HasMaxLength(128);
|
||||
|
||||
entity.HasOne(r => r.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(r => r.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
// SQLite does not support DateTimeOffset in ORDER BY clauses.
|
||||
// Convert all DateTimeOffset properties to Unix milliseconds (long) for storage.
|
||||
var dateTimeOffsetConverter = new ValueConverter<DateTimeOffset, long>(
|
||||
|
||||
Reference in New Issue
Block a user