feat: implement identity authentication, authorization policies, and MAUI platform support with Docker orchestration
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NexusReader.Application.Abstractions.Services;
|
||||
using NexusReader.Domain.Entities;
|
||||
using NexusReader.Infrastructure.Persistence;
|
||||
|
||||
namespace NexusReader.Infrastructure.Services;
|
||||
|
||||
public class BillingService : IBillingService
|
||||
{
|
||||
private readonly AppDbContext _dbContext;
|
||||
private readonly UserManager<NexusUser> _userManager;
|
||||
|
||||
public BillingService(AppDbContext dbContext, UserManager<NexusUser> userManager)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<bool> HandleSubscriptionUpdatedAsync(string customerEmail, string stripeProductId)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(customerEmail);
|
||||
if (user == null) return false;
|
||||
|
||||
// Map Stripe Product IDs to Nexus Plans
|
||||
// These IDs would typically come from configuration
|
||||
if (stripeProductId.Contains("pro"))
|
||||
{
|
||||
user.CurrentPlan = "Pro";
|
||||
user.AITokenLimit = 50000;
|
||||
}
|
||||
else if (stripeProductId.Contains("basic"))
|
||||
{
|
||||
user.CurrentPlan = "Basic";
|
||||
user.AITokenLimit = 10000;
|
||||
}
|
||||
|
||||
await _userManager.UpdateAsync(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> HandleSubscriptionDeletedAsync(string customerEmail)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(customerEmail);
|
||||
if (user == null) return false;
|
||||
|
||||
user.CurrentPlan = "Free";
|
||||
user.AITokenLimit = 1000; // Reset to free limit
|
||||
|
||||
await _userManager.UpdateAsync(user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user