[Local] Dockerized local test stack + always-show OTP in Development
Add docker-compose.local.yml + Dockerfile.local (public MS images + Liara NuGet) to run the whole app with a throwaway Postgres in one command for local testing, plus LOCAL.md. OtpService now never calls Kavenegar in the Development environment and always returns the code so the login page shows it on screen — guarantees local logins work with no SMS. Production behavior unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using JobsMedical.Web.Services.Scraping;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace JobsMedical.Web.Services;
|
||||
|
||||
@@ -13,12 +14,14 @@ public class OtpService
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly ISmsSender _sms;
|
||||
private readonly SettingsService _settings;
|
||||
private readonly IHostEnvironment _env;
|
||||
|
||||
public OtpService(IMemoryCache cache, ISmsSender sms, SettingsService settings)
|
||||
public OtpService(IMemoryCache cache, ISmsSender sms, SettingsService settings, IHostEnvironment env)
|
||||
{
|
||||
_cache = cache;
|
||||
_sms = sms;
|
||||
_settings = settings;
|
||||
_env = env;
|
||||
}
|
||||
|
||||
private static string Key(string phone) => $"otp:{Normalize(phone)}";
|
||||
@@ -33,12 +36,14 @@ public class OtpService
|
||||
_cache.Set(Key(phone), code, TimeSpan.FromMinutes(5));
|
||||
|
||||
var settings = await _settings.GetAsync();
|
||||
if (settings.SmsEnabled)
|
||||
// In Development (local Docker / dotnet run) never call the SMS gateway — always show the
|
||||
// code on the login screen. In Production, send via SMS only when it's enabled.
|
||||
if (settings.SmsEnabled && !_env.IsDevelopment())
|
||||
{
|
||||
await _sms.SendOtpAsync(phone, code, settings);
|
||||
return null; // never reveal the code in production
|
||||
return null; // sent via SMS — don't reveal it
|
||||
}
|
||||
return code; // dev: surface it on screen
|
||||
return code; // local/dev (or SMS off): surface it on screen
|
||||
}
|
||||
|
||||
public bool Verify(string phone, string code)
|
||||
|
||||
Reference in New Issue
Block a user