"Improve-product-UI-with-individual-bubbles-and-fix-admin-authentication"

This commit is contained in:
sysadmin
2025-08-28 00:22:27 +01:00
parent 5748ed4a09
commit 7e364b2a44
8 changed files with 171 additions and 4 deletions

View File

@@ -43,7 +43,8 @@ public class AccountController : Controller
var claims = new List<Claim>
{
new(ClaimTypes.Name, "admin"),
new(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString())
new(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()),
new(ClaimTypes.Role, "Admin")
};
var identity = new ClaimsIdentity(claims, "Cookies");

View File

@@ -0,0 +1,36 @@
@{
ViewData["Title"] = "Access Denied";
}
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-body text-center">
<div class="mb-4">
<i class="fas fa-lock fa-3x text-danger mb-3"></i>
<h2 class="text-danger">Access Denied</h2>
</div>
<div class="alert alert-danger" role="alert">
<strong>Unauthorized Access</strong><br>
You don't have permission to access this resource.
</div>
<p class="text-muted">
You need to log in with an administrator account to access the admin panel.
</p>
<div class="mt-4">
<a href="/Admin/Account/Login" class="btn btn-primary">
<i class="fas fa-sign-in-alt"></i> Login
</a>
<a href="/" class="btn btn-outline-secondary">
<i class="fas fa-home"></i> Home
</a>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using LittleShop.Services;
using LittleShop.DTOs;
using LittleShop.Data;
namespace LittleShop.Controllers;
@@ -10,11 +12,13 @@ public class TestController : ControllerBase
{
private readonly ICategoryService _categoryService;
private readonly IProductService _productService;
private readonly LittleShopContext _context;
public TestController(ICategoryService categoryService, IProductService productService)
public TestController(ICategoryService categoryService, IProductService productService, LittleShopContext context)
{
_categoryService = categoryService;
_productService = productService;
_context = context;
}
[HttpPost("create-product")]
@@ -86,4 +90,52 @@ public class TestController : ControllerBase
return BadRequest(new { error = ex.Message });
}
}
[HttpPost("cleanup-bots")]
public async Task<IActionResult> CleanupBots()
{
try
{
// Get count before cleanup
var totalBots = await _context.Bots.CountAsync();
// Keep only the most recent active bot per platform
var keepBots = await _context.Bots
.Where(b => b.IsActive && b.Status == Enums.BotStatus.Active)
.GroupBy(b => b.PlatformId)
.Select(g => g.OrderByDescending(b => b.LastSeenAt ?? b.CreatedAt).First())
.ToListAsync();
var keepBotIds = keepBots.Select(b => b.Id).ToList();
// Delete old/inactive bots and related data
var botsToDelete = await _context.Bots
.Where(b => !keepBotIds.Contains(b.Id))
.ToListAsync();
_context.Bots.RemoveRange(botsToDelete);
await _context.SaveChangesAsync();
var deletedCount = botsToDelete.Count;
var remainingCount = keepBots.Count;
return Ok(new {
message = "Bot cleanup completed",
totalBots = totalBots,
deletedBots = deletedCount,
remainingBots = remainingCount,
keptBots = keepBots.Select(b => new {
id = b.Id,
name = b.Name,
platformUsername = b.PlatformUsername,
lastSeen = b.LastSeenAt,
created = b.CreatedAt
})
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
}

Binary file not shown.

Binary file not shown.