yavsc/src/Yavsc/Controllers/HomeController.cs

135 lines
4.2 KiB
C#
Raw Normal View History

2016-05-17 18:22:18 +02:00
using Microsoft.AspNet.Mvc.Localization;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Hosting;
2016-09-23 12:28:38 +02:00
using Microsoft.AspNet.Identity;
using System.Linq;
using System.Security.Claims;
2017-01-24 10:43:42 +01:00
using Microsoft.Data.Entity;
2017-02-21 03:18:21 +01:00
using Microsoft.AspNet.Http;
using System.Threading.Tasks;
2016-05-17 18:22:18 +02:00
namespace Yavsc.Controllers
{
2017-09-13 22:32:17 +02:00
using System.IO;
2017-02-23 03:10:30 +01:00
using Models;
2017-05-27 16:22:58 +02:00
using Yavsc;
2017-09-24 23:42:41 +02:00
using Yavsc.Helpers;
2017-03-29 01:55:25 +02:00
[AllowAnonymous]
2016-05-17 18:22:18 +02:00
public class HomeController : Controller
{
2020-10-09 19:35:39 +01:00
readonly ApplicationDbContext _dbContext;
2016-05-17 18:22:18 +02:00
2019-07-25 14:52:44 +02:00
readonly IHtmlLocalizer _localizer;
2020-10-09 19:35:39 +01:00
public HomeController(IHtmlLocalizer<Startup> localizer,
ApplicationDbContext context)
2016-05-17 18:22:18 +02:00
{
_localizer = localizer;
2019-01-29 20:03:13 +00:00
_dbContext = context;
2016-05-17 18:22:18 +02:00
}
2017-02-21 03:18:21 +01:00
public async Task<IActionResult> Index(string id)
2016-05-17 18:22:18 +02:00
{
2020-10-09 19:35:39 +01:00
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(Constants.SshHeaderKey) && Request.Headers[Constants.SshHeaderKey] == "on";
2019-07-25 14:52:44 +02:00
ViewBag.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"];
2017-03-22 03:31:29 +01:00
ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey];
2017-02-21 03:18:21 +01:00
var uid = User.GetUserId();
2019-07-25 14:52:44 +02:00
long[] clicked = null;
if (uid == null)
{
2017-02-21 03:18:21 +01:00
await HttpContext.Session.LoadAsync();
var strclicked = HttpContext.Session.GetString("clicked");
2019-07-25 14:52:44 +02:00
if (strclicked != null) clicked = strclicked.Split(':').Select(c => long.Parse(c)).ToArray();
if (clicked == null) clicked = new long[0];
2017-02-21 03:18:21 +01:00
}
2019-07-25 14:52:44 +02:00
else clicked = _dbContext.DimissClicked.Where(d => d.UserId == uid).Select(d => d.NotificationId).ToArray();
2019-01-29 20:03:13 +00:00
var notes = _dbContext.Notification.Where(
2019-07-25 14:52:44 +02:00
n => !clicked.Contains(n.Id)
2017-02-21 03:18:21 +01:00
);
2017-09-24 23:42:41 +02:00
this.Notify(notes);
2019-07-25 14:52:44 +02:00
ViewData["HaircutCommandCount"] = _dbContext.HairCutQueries.Where(
q => q.ClientId == uid && q.Status < QueryStatus.Failed
2017-10-10 20:50:05 +02:00
).Count();
2019-07-25 14:52:44 +02:00
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();
}
2017-10-15 15:59:52 +02:00
return View(toShow);
2016-05-17 18:22:18 +02:00
}
2017-09-13 22:32:17 +02:00
public async Task<IActionResult> About()
2016-05-17 18:22:18 +02:00
{
2017-09-13 22:32:17 +02:00
FileInfo fi = new FileInfo("wwwroot/version");
2019-07-25 14:52:44 +02:00
return View("About", fi.Exists ? _localizer["Version logicielle: "] + await fi.OpenText().ReadToEndAsync() : _localizer["Aucune information sur la version logicielle n'est publiée."]);
2016-05-17 18:22:18 +02:00
}
2017-06-14 12:28:08 +02:00
public IActionResult Privacy()
{
return View();
}
2016-06-13 13:33:32 +02:00
public IActionResult AboutMarkdown()
{
return View();
}
2016-05-17 18:22:18 +02:00
public IActionResult Contact()
{
return View();
}
2021-10-17 20:09:54 +01:00
public IActionResult Dash()
{
return View();
}
2016-05-17 18:22:18 +02:00
public ActionResult Chat()
{
2019-07-25 14:52:44 +02:00
if (User.Identity.IsAuthenticated)
{
ViewBag.IsAuthenticated = true;
2016-09-23 12:28:38 +02:00
string uid = User.GetUserId();
2019-07-25 14:52:44 +02:00
ViewBag.Contacts = _dbContext.Contact.Where(c => c.OwnerId == uid)
2016-09-23 12:28:38 +02:00
;
2019-07-25 14:52:44 +02:00
}
else ViewBag.IsAuthenticated = false;
2016-05-17 18:22:18 +02:00
return View();
}
public IActionResult Error()
{
var feature = this.HttpContext.Features.Get<IExceptionHandlerFeature>();
return View("~/Views/Shared/Error.cshtml", feature?.Error);
}
public IActionResult Status(int id)
{
ViewBag.StatusCode = id;
2019-07-25 14:52:44 +02:00
return View("~/Views/Shared/Status.cshtml");
2016-05-17 18:22:18 +02:00
}
2019-07-25 14:52:44 +02:00
public IActionResult Todo()
{
2017-06-20 02:47:52 +02:00
User.GetUserId();
2019-07-25 14:52:44 +02:00
return View();
}
2019-07-25 14:52:44 +02:00
public IActionResult VideoChat()
{
return View();
}
2016-05-17 18:22:18 +02:00
2019-07-25 14:52:44 +02:00
public IActionResult Audio()
{
return View();
}
2019-07-25 14:52:44 +02:00
}
2016-05-17 18:22:18 +02:00
}