2023-03-19 17:57:55 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Yavsc.Models;
|
2023-03-26 20:41:42 +01:00
|
|
|
using Yavsc.Helpers;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Localization;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2025-07-15 19:43:41 +01:00
|
|
|
using Yavsc.Server.Helpers;
|
2016-05-17 18:22:18 +02:00
|
|
|
|
2023-03-26 20:41:42 +01:00
|
|
|
namespace Yavsc.Controllers
|
2016-05-17 18:22:18 +02:00
|
|
|
{
|
2017-03-29 01:55:25 +02:00
|
|
|
|
2023-03-26 20:41:42 +01:00
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class HomeController : Controller
|
2016-05-17 18:22:18 +02:00
|
|
|
{
|
2023-03-26 20:41:42 +01:00
|
|
|
readonly ApplicationDbContext _dbContext;
|
2026-07-12 17:56:23 +01:00
|
|
|
readonly ILogger<HomeController> _logger;
|
|
|
|
|
private readonly bool _isDevelopment;
|
2023-03-26 20:41:42 +01:00
|
|
|
readonly IHtmlLocalizer _localizer;
|
2016-05-17 18:22:18 +02:00
|
|
|
|
2023-03-26 20:41:42 +01:00
|
|
|
private SiteSettings siteSettings;
|
|
|
|
|
public HomeController(ILogger<HomeController> logger,
|
2026-02-22 23:39:56 +00:00
|
|
|
IHtmlLocalizer<HomeController> localizer,
|
2023-03-26 20:41:42 +01:00
|
|
|
ApplicationDbContext context,
|
2026-07-12 17:56:23 +01:00
|
|
|
IOptions<SiteSettings> settingsOptions,
|
|
|
|
|
IWebHostEnvironment env
|
|
|
|
|
)
|
2023-03-26 20:41:42 +01:00
|
|
|
{
|
|
|
|
|
_localizer = localizer;
|
|
|
|
|
_dbContext = context;
|
|
|
|
|
siteSettings = settingsOptions.Value;
|
2026-07-12 17:56:23 +01:00
|
|
|
_logger = logger;
|
|
|
|
|
_isDevelopment = env.IsDevelopment();
|
|
|
|
|
|
2023-03-26 20:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> Index(string id)
|
|
|
|
|
{
|
2026-05-30 19:34:22 +01:00
|
|
|
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(YavscConstants.SshHeaderKey) && Request.Headers[YavscConstants.SshHeaderKey] == "on";
|
2023-03-26 20:41:42 +01:00
|
|
|
ViewBag.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"];
|
2026-05-30 19:34:22 +01:00
|
|
|
ViewBag.SshHeaderKey = Request.Headers[YavscConstants.SshHeaderKey];
|
2023-03-26 20:41:42 +01:00
|
|
|
var uid = User.GetUserId();
|
|
|
|
|
long[] clicked = null;
|
|
|
|
|
if (uid == null)
|
|
|
|
|
{
|
2024-11-06 13:00:34 +00:00
|
|
|
// await HttpContext.Session.LoadAsync();
|
2023-03-26 20:41:42 +01:00
|
|
|
var strclicked = HttpContext.Session.GetString("clicked");
|
|
|
|
|
if (strclicked != null) clicked = strclicked.Split(':').Select(c => long.Parse(c)).ToArray();
|
|
|
|
|
if (clicked == null) clicked = new long[0];
|
|
|
|
|
}
|
2024-11-06 13:00:34 +00:00
|
|
|
else clicked = _dbContext.DismissClicked.Where(d => d.UserId == uid).Select(d => d.NotificationId).ToArray();
|
2023-03-26 20:41:42 +01:00
|
|
|
var notes = _dbContext.Notification.Where(
|
|
|
|
|
n => !clicked.Contains(n.Id)
|
|
|
|
|
);
|
|
|
|
|
if (notes.Any()) this.Notify(notes);
|
|
|
|
|
|
|
|
|
|
var toShow = _dbContext.Activities
|
|
|
|
|
.Include(a => a.Forms)
|
|
|
|
|
.Include(a => a.Parent)
|
|
|
|
|
.Include(a => a.Children)
|
|
|
|
|
.Where(a => !a.Hidden)
|
|
|
|
|
.Where(a => a.ParentCode == id)
|
|
|
|
|
.OrderByDescending(a => a.Rate).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var a in toShow)
|
|
|
|
|
{
|
|
|
|
|
a.Children = a.Children.Where(c => !c.Hidden).ToList();
|
|
|
|
|
}
|
|
|
|
|
return View(toShow);
|
|
|
|
|
}
|
|
|
|
|
public async Task<IActionResult> About()
|
|
|
|
|
{
|
2024-11-23 14:23:47 +00:00
|
|
|
return View("About");
|
2023-03-26 20:41:42 +01:00
|
|
|
}
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
public IActionResult AboutMarkdown()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Contact()
|
|
|
|
|
{
|
2025-09-14 22:43:40 +01:00
|
|
|
return View(siteSettings);
|
2023-03-26 20:41:42 +01:00
|
|
|
}
|
|
|
|
|
public IActionResult Dash()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
public ActionResult Chat()
|
|
|
|
|
{
|
|
|
|
|
if (User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
ViewBag.IsAuthenticated = true;
|
|
|
|
|
string uid = User.GetUserId();
|
|
|
|
|
ViewBag.Contacts = _dbContext.Contact.Where(c => c.OwnerId == uid)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
else ViewBag.IsAuthenticated = false;
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
2026-07-12 17:56:23 +01:00
|
|
|
if (_isDevelopment)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation(
|
|
|
|
|
"Home/Error requested in Development. This endpoint is disabled because DeveloperExceptionPage should handle unhandled exceptions.");
|
|
|
|
|
|
|
|
|
|
return NotFound(
|
|
|
|
|
"In Development, /Home/Error is disabled. Unhandled exceptions are rendered by DeveloperExceptionPage.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var errorViewModel = new ErrorViewModel
|
|
|
|
|
{
|
|
|
|
|
RequestId = HttpContext.TraceIdentifier
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var exceptionHandlerPathFeature =
|
|
|
|
|
HttpContext.Features.Get<IExceptionHandlerPathFeature>();
|
|
|
|
|
|
|
|
|
|
if (exceptionHandlerPathFeature is null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning(
|
|
|
|
|
"Home/Error called without IExceptionHandlerPathFeature in non-development environment.");
|
|
|
|
|
|
|
|
|
|
return View("~/Views/Shared/Error.cshtml", errorViewModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
errorViewModel.Description = "The file was not found.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exceptionHandlerPathFeature?.Path == "/")
|
2025-09-14 00:41:35 +01:00
|
|
|
{
|
2026-07-12 17:56:23 +01:00
|
|
|
errorViewModel.Description ??= string.Empty;
|
|
|
|
|
errorViewModel.Description += " Page: Home.";
|
2025-09-14 00:41:35 +01:00
|
|
|
}
|
2026-07-12 17:56:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
return View("~/Views/Shared/Error.cshtml", errorViewModel);
|
2023-03-26 20:41:42 +01:00
|
|
|
}
|
|
|
|
|
public IActionResult Status(int id)
|
|
|
|
|
{
|
|
|
|
|
ViewBag.StatusCode = id;
|
|
|
|
|
return View("~/Views/Shared/Status.cshtml");
|
|
|
|
|
}
|
|
|
|
|
public IActionResult Todo()
|
|
|
|
|
{
|
|
|
|
|
User.GetUserId();
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult VideoChat()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Audio()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2018-03-23 13:51:48 +01:00
|
|
|
|
2019-07-25 14:52:44 +02:00
|
|
|
}
|
2016-05-17 18:22:18 +02:00
|
|
|
}
|