initialize admin panel and necessry pages
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using GreenHome.Application;
|
||||
using GreenHome.Infrastructure.Data;
|
||||
using GreenHome.Infrastructure.Services.Usage;
|
||||
using GreenHome.Sms.Ippanel;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -13,6 +14,7 @@ public sealed class AuthService : IAuthService
|
||||
{
|
||||
private readonly GreenHomeDbContext _dbContext;
|
||||
private readonly ISmsService _smsService;
|
||||
private readonly UsageTracker _usageTracker;
|
||||
private readonly ILogger<AuthService> _logger;
|
||||
private readonly string _tokenSecret;
|
||||
private const int CodeExpirationMinutes = 5;
|
||||
@@ -21,11 +23,13 @@ public sealed class AuthService : IAuthService
|
||||
public AuthService(
|
||||
GreenHomeDbContext dbContext,
|
||||
ISmsService smsService,
|
||||
UsageTracker usageTracker,
|
||||
IConfiguration configuration,
|
||||
ILogger<AuthService> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_smsService = smsService;
|
||||
_usageTracker = usageTracker;
|
||||
_logger = logger;
|
||||
_tokenSecret = configuration["Auth:TokenSecret"] ?? "greenhome-dev-secret-change-me";
|
||||
}
|
||||
@@ -45,6 +49,19 @@ public sealed class AuthService : IAuthService
|
||||
};
|
||||
}
|
||||
|
||||
var existingUser = await _dbContext.Users
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(u => u.Mobile == mobile, cancellationToken);
|
||||
|
||||
if (existingUser != null && existingUser.IsDisabled)
|
||||
{
|
||||
return new SendCodeResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "حساب شما غیرفعال شده است. لطفاً با پشتیبانی تماس بگیرید."
|
||||
};
|
||||
}
|
||||
|
||||
var canResend = await CanResendCodeAsync(mobile, cancellationToken);
|
||||
if (!canResend)
|
||||
{
|
||||
@@ -98,6 +115,9 @@ public sealed class AuthService : IAuthService
|
||||
Variables = new Dictionary<string, string> { { "code", code } }
|
||||
}, cancellationToken);
|
||||
|
||||
if (existingUser != null)
|
||||
await _usageTracker.RecordAsync(existingUser.Id, UsageKind.Sms, cancellationToken: cancellationToken);
|
||||
|
||||
_logger.LogInformation("Verification code sent to {Mobile}", mobile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -149,6 +169,15 @@ public sealed class AuthService : IAuthService
|
||||
var user = await _dbContext.Users
|
||||
.FirstOrDefaultAsync(u => u.Mobile == mobile, cancellationToken);
|
||||
|
||||
if (user != null && user.IsDisabled)
|
||||
{
|
||||
return new VerifyCodeResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "حساب شما غیرفعال شده است. لطفاً با پشتیبانی تماس بگیرید."
|
||||
};
|
||||
}
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
user = new Domain.User
|
||||
@@ -179,7 +208,8 @@ public sealed class AuthService : IAuthService
|
||||
Mobile = user.Mobile,
|
||||
Name = user.Name,
|
||||
Family = user.Family,
|
||||
Role = user.Role
|
||||
Role = user.Role,
|
||||
IsDisabled = user.IsDisabled
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -233,13 +263,17 @@ public sealed class AuthService : IAuthService
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
if (user.IsDisabled)
|
||||
return null;
|
||||
|
||||
return new UserDto
|
||||
{
|
||||
Id = user.Id,
|
||||
Mobile = user.Mobile,
|
||||
Name = user.Name,
|
||||
Family = user.Family,
|
||||
Role = user.Role
|
||||
Role = user.Role,
|
||||
IsDisabled = user.IsDisabled
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user