Generator Changes at 9/28/2025 6:19:21 AM

This commit is contained in:
MeysamMoghaddam
2025-09-28 06:30:13 +03:30
parent 1a99a88552
commit a3b7302d90
16 changed files with 534 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ public interface IApplicationDbContext
DbSet<UserOrder> UserOrders { get; }
DbSet<Role> Roles { get; }
DbSet<UserRole> UserRoles { get; }
DbSet<User> Users { get; }
DbSet<OtpToken> OtpTokens { get; }
DbSet<User> Users { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}

View File

@@ -14,7 +14,9 @@ public class CreateNewOtpTokenCommandHandler : IRequestHandler<CreateNewOtpToken
_cfg = cfg;
}
const int CodeLength = 6; // 4-6 مناسب است
const int CodeLength = 6;
const int MaxAttempts = 5; // محدودیت تلاش
static readonly TimeSpan Ttl = TimeSpan.FromMinutes(2);
static readonly TimeSpan Cooldown = TimeSpan.FromSeconds(60); // فاصله ارسال مجدد
public async Task<CreateNewOtpTokenResponseDto> Handle(CreateNewOtpTokenCommand request,
@@ -57,7 +59,9 @@ public class CreateNewOtpTokenCommandHandler : IRequestHandler<CreateNewOtpToken
{
Success = true,
Message = "کد ارسال شد.",
Code = code
Code = code,
RemainingAttempts = MaxAttempts,
RemainingSeconds = Ttl.Seconds
};
}

View File

@@ -7,5 +7,9 @@ public class CreateNewOtpTokenResponseDto
public string Message { get; set; }
//کد
public string? Code { get; set; }
//تلاش باقی مانده
public int RemainingAttempts { get; set; }
//ثانیه باقی مانده
public int RemainingSeconds { get; set; }
}

View File

@@ -51,7 +51,9 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
Mobile = mobile,
ReferralCode = UtilExtensions.Generate(digits: 10, firstDigitNonZero: true),
IsMobileVerified = true,
MobileVerifiedAt = now
MobileVerifiedAt = now,
IsRulesAccepted = true,
RulesAcceptedAt = now,
};
await _context.Users.AddAsync(user, cancellationToken);
user.AddDomainEvent(new CreateNewUserEvent(user));
@@ -71,7 +73,9 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
{
Success = true,
Message = "اعتبارسنجی موفق.",
UserId = user.Id
UserId = user.Id,
RemainingAttempts = MaxAttempts,
RemainingSeconds = (otp.ExpiresAt - now).Seconds
};
}

View File

@@ -7,5 +7,9 @@ public class VerifyOtpTokenResponseDto
public string Message { get; set; }
//شناسه کاربر
public long? UserId { get; set; }
//تلاش باقی مانده
public int RemainingAttempts { get; set; }
//ثانیه باقی مانده
public int RemainingSeconds { get; set; }
}

View File

@@ -11,5 +11,9 @@ public record UpdateUserCommand : IRequest<Unit>
public string? NationalCode { get; init; }
//آدرس آواتار
public string? AvatarPath { get; init; }
//قوانین پذیرفته شده؟
public bool IsRulesAccepted { get; init; }
//تاریخ پذیرش قوانین
public DateTime? RulesAcceptedAt { get; init; }
}

View File

@@ -5,6 +5,8 @@ public class UpdateUserCommandValidator : AbstractValidator<UpdateUserCommand>
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.IsRulesAccepted)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{