feat: integrate Serilog and Telegram notifications
TaxBaik CI/CD / build-and-deploy (push) Successful in 51s
TaxBaik CI/CD / build-and-deploy (push) Successful in 51s
- Add Serilog for structured logging (Console + File) - Implement TelegramNotificationService for admin alerts - Log successful/failed login attempts with Telegram notifications - Add application startup/shutdown logging - Log important events to Telegram Chat ID: -5585148480 - Configuration: Telegram:BotToken and Telegram:ChatId in appsettings Features: - Automatic daily log rotation - Structured logging with timestamps - Environment-aware alerts - Error and info level Telegram messages Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,15 +12,21 @@ public class AuthService
|
||||
{
|
||||
private readonly IAdminUserRepository _adminUserRepository;
|
||||
private readonly ILogger<AuthService> _logger;
|
||||
private readonly ITelegramNotificationService _telegramService;
|
||||
private readonly string _jwtSecretKey;
|
||||
private readonly string? _passwordResetToken;
|
||||
private readonly int _accessTokenExpirationMinutes = 60; // Access Token: 1시간 (사용성 향상)
|
||||
private readonly int _refreshTokenExpirationMinutes = 10080; // Refresh Token: 7일
|
||||
|
||||
public AuthService(IAdminUserRepository adminUserRepository, ILogger<AuthService> logger, IConfiguration configuration)
|
||||
public AuthService(
|
||||
IAdminUserRepository adminUserRepository,
|
||||
ILogger<AuthService> logger,
|
||||
IConfiguration configuration,
|
||||
ITelegramNotificationService telegramService)
|
||||
{
|
||||
_adminUserRepository = adminUserRepository;
|
||||
_logger = logger;
|
||||
_telegramService = telegramService;
|
||||
_jwtSecretKey = configuration["Jwt:SecretKey"] ?? throw new InvalidOperationException("Missing 'Jwt:SecretKey' configuration.");
|
||||
_passwordResetToken = configuration["Admin:PasswordResetToken"];
|
||||
}
|
||||
@@ -46,10 +52,16 @@ public class AuthService
|
||||
if (!BCrypt.Net.BCrypt.Verify(password, user.PasswordHash))
|
||||
{
|
||||
_logger.LogWarning("로그인 시도: 잘못된 비밀번호 '{Username}'", username);
|
||||
await _telegramService.SendErrorAsync(
|
||||
"로그인 실패",
|
||||
$"사용자: {username}\n실패 사유: 잘못된 비밀번호");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("로그인 성공: {Username}", username);
|
||||
await _telegramService.SendInfoAsync(
|
||||
"관리자 로그인",
|
||||
$"사용자: {username}");
|
||||
await _adminUserRepository.UpdateLastLoginAtAsync(user.Id);
|
||||
return GenerateTokenPair(user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user