yavsc/src/Yavsc/Controllers/HomeController.cs

131 lines
4.3 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;
2019-05-06 13:05:58 +01:00
using Microsoft.AspNet.Builder;
2016-09-23 12:28:38 +02:00
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
{
2019-01-29 20:03:13 +00:00
IHostingEnvironment _hosting;
2016-05-17 18:22:18 +02:00
2019-01-29 20:03:13 +00:00
ApplicationDbContext _dbContext;
2016-05-17 18:22:18 +02:00
2019-01-29 20:03:13 +00:00
readonly IHtmlLocalizer _localizer;
2016-09-23 12:28:38 +02:00
public HomeController(IHtmlLocalizer<Startup> localizer, IHostingEnvironment hosting,
ApplicationDbContext context, UserManager<ApplicationUser> userManager)
2016-05-17 18:22:18 +02:00
{
_localizer = localizer;
2019-01-29 20:03:13 +00:00
_hosting = hosting;
_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
{
2019-01-29 20:03:13 +00:00
ViewBag.IsFromSecureProx = (Request.Headers.ContainsKey(Constants.SshHeaderKey))? Request.Headers[Constants.SshHeaderKey]=="on" : false ;
2017-03-22 03:31:29 +01:00
ViewBag.SecureHomeUrl = "https://"+Request.Headers["X-Forwarded-Host"];
ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey];
2017-02-21 03:18:21 +01:00
var uid = User.GetUserId();
long [] clicked=null;
if (uid==null) {
await HttpContext.Session.LoadAsync();
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];
}
2019-01-29 20:03:13 +00:00
else clicked = _dbContext.DimissClicked.Where(d=>d.UserId == uid).Select(d=>d.NotificationId).ToArray();
var notes = _dbContext.Notification.Where(
2018-02-03 20:17:29 +01: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-01-29 20:03:13 +00:00
ViewData["HaircutCommandCount"] = _dbContext.HairCutQueries.Where(
2017-10-10 20:50:05 +02:00
q=>q.ClientId == uid && q.Status < QueryStatus.Failed
).Count();
2019-01-29 20:03:13 +00:00
var toShow = _dbContext.Activities
2017-10-15 15:59:52 +02:00
.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);
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");
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();
}
public ActionResult Chat()
{
2016-09-23 12:28:38 +02:00
if (User.Identity.IsAuthenticated) {
2016-11-01 23:21:03 +01:00
ViewBag.IsAuthenticated=true;
2016-09-23 12:28:38 +02:00
string uid = User.GetUserId();
2019-01-29 20:03:13 +00:00
ViewBag.Contacts = _dbContext.Contacts.Where(c=>c.OwnerId == uid)
2016-09-23 12:28:38 +02:00
;
2016-11-01 23:21:03 +01: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;
return View("~/Views/Shared/Status.cshtml");
}
public IActionResult Todo()
{
2017-06-20 02:47:52 +02:00
User.GetUserId();
2016-05-17 18:22:18 +02:00
return View();
}
2017-08-31 17:36:45 +02:00
public IActionResult VideoChat()
{
return View();
}
2016-05-17 18:22:18 +02:00
public IActionResult Audio()
{
return View();
}
}
2016-05-17 18:22:18 +02:00
}