306 lines
12 KiB
C#
306 lines
12 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using QRRapidoApp.Models;
|
||
using QRRapidoApp.Services;
|
||
using System.Diagnostics;
|
||
using System.Security.Claims;
|
||
using Microsoft.Extensions.Localization;
|
||
|
||
namespace QRRapidoApp.Controllers
|
||
{
|
||
public class HomeController : Controller
|
||
{
|
||
private readonly ILogger<HomeController> _logger;
|
||
private readonly AdDisplayService _adDisplayService;
|
||
private readonly IUserService _userService;
|
||
private readonly IConfiguration _config;
|
||
private readonly IStringLocalizer<QRRapidoApp.Resources.SharedResource> _localizer;
|
||
|
||
public HomeController(
|
||
ILogger<HomeController> logger,
|
||
AdDisplayService adDisplayService,
|
||
IUserService userService,
|
||
IConfiguration config,
|
||
IStringLocalizer<QRRapidoApp.Resources.SharedResource> localizer
|
||
)
|
||
{
|
||
_logger = logger;
|
||
_adDisplayService = adDisplayService;
|
||
_userService = userService;
|
||
_config = config;
|
||
_localizer = localizer;
|
||
}
|
||
|
||
public async Task<IActionResult> Index()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = await _adDisplayService.ShouldShowAds(userId);
|
||
ViewBag.IsPremium = await _adDisplayService.HasValidPremiumSubscription(userId ?? "");
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
// SEO and Analytics data
|
||
ViewBag.Title = _config["App:TaglinePT"];
|
||
ViewBag.Keywords = _config["SEO:KeywordsPT"];
|
||
ViewBag.Description = _localizer["QRGenerateDescription"];
|
||
|
||
// User stats for logged in users
|
||
if (!string.IsNullOrEmpty(userId))
|
||
{
|
||
ViewBag.DailyQRCount = await _userService.GetDailyQRCountAsync(userId);
|
||
ViewBag.MonthlyQRCount = await _userService.GetQRCountThisMonthAsync(userId);
|
||
}
|
||
|
||
return View();
|
||
}
|
||
|
||
public IActionResult Privacy()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result;
|
||
ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result;
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
|
||
ViewBag.Title = _localizer["PrivacyPolicyTitle"];
|
||
ViewBag.Description = _localizer["PrivacyPolicyDescription"];
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
return View();
|
||
}
|
||
|
||
public IActionResult Terms()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result;
|
||
ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result;
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
|
||
ViewBag.Title = _localizer["TermsOfUseTitle"];
|
||
ViewBag.Description = _localizer["TermsOfUseDescription"];
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
return View();
|
||
}
|
||
|
||
public IActionResult About()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result;
|
||
ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result;
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
|
||
ViewBag.Title = _localizer["AboutPageTitle"];
|
||
ViewBag.Description = _localizer["AboutPageDescription"];
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
return View();
|
||
}
|
||
|
||
public IActionResult Contact()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result;
|
||
ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result;
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
|
||
ViewBag.Title = _localizer["ContactPageTitle"];
|
||
ViewBag.Description = _localizer["ContactPageDescription"];
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
return View();
|
||
}
|
||
|
||
public IActionResult FAQ()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result;
|
||
ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result;
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
|
||
ViewBag.Title = _localizer["FAQPageTitle"];
|
||
ViewBag.Description = _localizer["FAQPageDescription"];
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
return View();
|
||
}
|
||
|
||
public IActionResult HowToUse()
|
||
{
|
||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
|
||
ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result;
|
||
ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result;
|
||
ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false;
|
||
ViewBag.UserName = User.Identity?.Name ?? "";
|
||
|
||
ViewBag.Title = _localizer["HowToUsePageTitle"];
|
||
ViewBag.Description = _localizer["HowToUsePageDescription"];
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
|
||
return View();
|
||
}
|
||
|
||
//[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||
//public IActionResult Error()
|
||
//{
|
||
// return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||
//}
|
||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||
public IActionResult Error()
|
||
{
|
||
var errorCode = Request.Query["code"].ToString();
|
||
var errorMessage = "";
|
||
|
||
// Interpretar c<>digos de erro espec<65>ficos
|
||
if (errorCode.StartsWith("M.C506"))
|
||
{
|
||
errorMessage = "Erro de autentica<63><61>o. Verifique suas credenciais e tente novamente.";
|
||
}
|
||
|
||
ViewBag.ErrorCode = errorCode;
|
||
ViewBag.ErrorMessage = errorMessage;
|
||
|
||
return View(new ErrorViewModel
|
||
{
|
||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
||
});
|
||
}
|
||
|
||
// Dynamic QR redirect endpoint
|
||
[Route("d/{id}")]
|
||
public async Task<IActionResult> DynamicRedirect(string id)
|
||
{
|
||
try
|
||
{
|
||
_adDisplayService.SetViewBagAds(ViewBag);
|
||
// This would lookup the dynamic QR content from cache/database
|
||
// For now, return a placeholder
|
||
return Redirect("https://qrrapido.site");
|
||
}
|
||
catch
|
||
{
|
||
return NotFound();
|
||
}
|
||
}
|
||
|
||
// Health check endpoint
|
||
[Route("health")]
|
||
public IActionResult Health()
|
||
{
|
||
return Ok(new { status = "healthy", timestamp = DateTime.UtcNow });
|
||
}
|
||
|
||
// Sitemap endpoint for SEO
|
||
[Route("sitemap.xml")]
|
||
public IActionResult Sitemap()
|
||
{
|
||
var sitemap = $@"<?xml version=""1.0"" encoding=""UTF-8""?>
|
||
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">
|
||
<url>
|
||
<loc>https://qrrapido.site/</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>daily</changefreq>
|
||
<priority>1.0</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/pt/</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>daily</changefreq>
|
||
<priority>0.9</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/es/</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>daily</changefreq>
|
||
<priority>0.9</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/pt-BR/About</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>monthly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/es-PY/About</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>monthly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/pt-BR/Contact</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>monthly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/es-PY/Contact</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>monthly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/pt-BR/FAQ</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>weekly</changefreq>
|
||
<priority>0.9</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/es-PY/FAQ</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>weekly</changefreq>
|
||
<priority>0.9</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/pt-BR/HowToUse</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>weekly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/es-PY/HowToUse</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>weekly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/Premium/Upgrade</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>weekly</changefreq>
|
||
<priority>0.8</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/privacy</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>monthly</changefreq>
|
||
<priority>0.5</priority>
|
||
</url>
|
||
<url>
|
||
<loc>https://qrrapido.site/terms</loc>
|
||
<lastmod>{DateTime.UtcNow:yyyy-MM-dd}</lastmod>
|
||
<changefreq>monthly</changefreq>
|
||
<priority>0.5</priority>
|
||
</url>
|
||
</urlset>";
|
||
|
||
return Content(sitemap, "application/xml");
|
||
}
|
||
}
|
||
|
||
//public class ErrorViewModel
|
||
//{
|
||
// public string? RequestId { get; set; }
|
||
// public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||
//}
|
||
} |