From 996f207c48f6d0567ed222a11b955de171102c32 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Mon, 1 Dec 2025 23:30:12 +0000 Subject: [PATCH] feat: Add PublicBotsController for anonymous ShareCard access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created PublicBotsController with [AllowAnonymous] at class level to avoid policy authorization conflicts with the main BotsController - Updated ShareCard.cshtml to use PublicBots controller for embed links - Fixes HTTP 500 error when accessing ShareCard without authentication 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Admin/Controllers/PublicBotsController.cs | 66 +++++++++++++++++++ .../Areas/Admin/Views/Bots/ShareCard.cshtml | 6 +- 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 LittleShop/Areas/Admin/Controllers/PublicBotsController.cs diff --git a/LittleShop/Areas/Admin/Controllers/PublicBotsController.cs b/LittleShop/Areas/Admin/Controllers/PublicBotsController.cs new file mode 100644 index 0000000..e774ae4 --- /dev/null +++ b/LittleShop/Areas/Admin/Controllers/PublicBotsController.cs @@ -0,0 +1,66 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using LittleShop.Services; + +namespace LittleShop.Areas.Admin.Controllers; + +/// +/// Public-facing bot pages that don't require authentication. +/// These are separated from the main BotsController to avoid authorization conflicts. +/// +[Area("Admin")] +[AllowAnonymous] +public class PublicBotsController : Controller +{ + private readonly IBotService _botService; + + public PublicBotsController(IBotService botService) + { + _botService = botService; + } + + // GET: Admin/PublicBots/ShareCard/5 + public async Task ShareCard(Guid id) + { + var bot = await _botService.GetBotByIdAsync(id); + if (bot == null) + return NotFound(); + + // Build the tg.me link + var telegramLink = !string.IsNullOrEmpty(bot.PlatformUsername) + ? $"https://t.me/{bot.PlatformUsername}" + : null; + + ViewData["TelegramLink"] = telegramLink; + + // Get review stats (TODO: Replace with actual review data from database) + // For now using sample data - in production, query from Reviews table + ViewData["ReviewCount"] = 127; + ViewData["AverageRating"] = 4.8m; + + return View("~/Areas/Admin/Views/Bots/ShareCard.cshtml", bot); + } + + // GET: Admin/PublicBots/ShareCardEmbed/5 + public async Task ShareCardEmbed(Guid id) + { + var bot = await _botService.GetBotByIdAsync(id); + if (bot == null) + return NotFound(); + + // Build the tg.me link + var telegramLink = !string.IsNullOrEmpty(bot.PlatformUsername) + ? $"https://t.me/{bot.PlatformUsername}" + : null; + + ViewData["TelegramLink"] = telegramLink; + + // Get review stats + ViewData["ReviewCount"] = 127; + ViewData["AverageRating"] = 4.8m; + + return View("~/Areas/Admin/Views/Bots/ShareCardEmbed.cshtml", bot); + } +} diff --git a/LittleShop/Areas/Admin/Views/Bots/ShareCard.cshtml b/LittleShop/Areas/Admin/Views/Bots/ShareCard.cshtml index 4eed644..77b9a4f 100644 --- a/LittleShop/Areas/Admin/Views/Bots/ShareCard.cshtml +++ b/LittleShop/Areas/Admin/Views/Bots/ShareCard.cshtml @@ -446,7 +446,7 @@ Back to Details - + View Public Card
- +