ENEI2019-Public/api/Controllers/mvcController.cs

189 lines
4.6 KiB
C#
Raw Normal View History

2018-12-12 15:17:08 +00:00
using System.Threading.Tasks;
using api.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using api.Dtos;
using Microsoft.AspNetCore.Identity;
using api.Models;
2019-04-06 21:17:49 +01:00
using System.Net.Http;
2019-04-11 05:35:49 +01:00
using AutoMapper;
using System.Collections.Generic;
2018-12-12 15:17:08 +00:00
namespace api.Controllers
{
[ApiController]
[Route("/")]
public class mvcController : Controller
{
2019-04-11 05:35:49 +01:00
private readonly IUsersRepository _repo;
2018-12-12 15:17:08 +00:00
private readonly DataContext _context;
private readonly UserManager<User> _userManager;
2019-04-11 05:35:49 +01:00
private readonly IMapper _mapper;
public mvcController(IUsersRepository repo, DataContext context, IMapper mapper, UserManager<User> userManager)
2018-12-12 15:17:08 +00:00
{
2019-04-11 05:35:49 +01:00
_mapper = mapper;
2019-04-06 00:37:03 +01:00
_context = context;
2018-12-12 15:17:08 +00:00
_userManager = userManager;
2019-04-11 05:35:49 +01:00
_repo = repo;
2018-12-12 15:17:08 +00:00
}
2019-04-10 18:16:07 +01:00
[HttpGet("/cp-ia")]
[AllowAnonymous]
public IActionResult cpIa()
{
return View("Views/Landing/cp-ia.cshtml");
}
[HttpGet("/cp-net")]
[AllowAnonymous]
public IActionResult cpNet()
{
return View("Views/Landing/cp-net.cshtml");
}
2019-04-12 15:40:32 +01:00
[HttpGet("/cp-md")]
[AllowAnonymous]
public IActionResult cpMd()
{
return View("Views/Landing/cp-md.cshtml");
}
2019-04-10 18:16:07 +01:00
[HttpGet("/cp-iot")]
[AllowAnonymous]
2018-12-12 15:17:08 +00:00
2019-04-10 18:16:07 +01:00
public IActionResult cpIot()
{
return View("Views/Landing/cp-iot.cshtml");
}
[HttpGet("/cp-ds")]
[AllowAnonymous]
public IActionResult cpDs()
{
return View("Views/Landing/cp-ds.cshtml");
}
[HttpGet("/cp-web")]
[AllowAnonymous]
public IActionResult cpWeb()
{
return View("Views/Landing/cp-web.cshtml");
}
2019-04-08 19:49:06 +01:00
[HttpGet("/jogoenei")]
[AllowAnonymous]
2019-04-10 18:16:07 +01:00
2019-04-08 20:18:51 +01:00
public IActionResult jogoENEI()
{
return View("Views/Landing/jogo.cshtml");
2019-04-08 19:49:06 +01:00
}
2019-04-10 18:16:07 +01:00
2019-04-11 05:35:49 +01:00
[AllowAnonymous]
[HttpGet("/ctf/top")]
public async Task<IActionResult> getTop()
{
//para cada user calcular pontos, fazer update e devolver top 5
// var users = await _repo.GetUsers();
// var usersToReturn = _mapper.Map<IEnumerable<UserForListDto>>(users);
var users = _context.Users.Select(user => new {Nome = user.fullName, Pontos = user.food }).OrderByDescending(x => x.Pontos).Take(10);;
//food = soma ctf
//drinks = soma geral
return Ok(users);
}
2019-04-08 19:49:06 +01:00
[HttpGet("/level1ctf")]
2018-12-12 15:17:08 +00:00
[AllowAnonymous]
2019-04-08 20:18:51 +01:00
public IActionResult level1()
{
return View("Views/Landing/1stpage.cshtml");
2019-04-08 19:49:06 +01:00
}
2019-04-10 18:16:07 +01:00
2019-04-08 20:18:51 +01:00
2019-04-12 22:45:46 +01:00
[HttpGet("/qsowde")]
[AllowAnonymous]
public IActionResult flag()
{
return Redirect("https://drive.google.com/file/d/1lXjuUJG0srIP-P58NDKq_EVV1slQR230/view?usp=sharing");
// return View("Views/Landing/1stpage.cshtml");
}
2019-04-08 20:18:51 +01:00
[AllowAnonymous]
2019-04-08 19:49:06 +01:00
[HttpGet("")]
2019-04-06 00:37:03 +01:00
public IActionResult landingPage()
{
2018-12-12 15:17:08 +00:00
return View("Views/Landing/index.cshtml");
}
2019-04-08 20:18:51 +01:00
2019-04-06 21:17:49 +01:00
[AllowAnonymous]
[HttpGet("/reset/{user}")]
public async Task<IActionResult> resetPassword(string user)
{
2019-04-08 20:18:51 +01:00
2019-04-06 21:17:49 +01:00
using (var client = new HttpClient())
{
try
{
var url = "https://tickets.enei.pt/internal/api/User/ResetPassword?code=" + user;
// client.DefaultRequestHeaders.Add("Authorization", "Bearer " + a.token);
var response = await client.GetStringAsync(url);
2019-04-08 20:18:51 +01:00
2019-04-06 21:17:49 +01:00
return View("Views/Landing/resetPage.cshtml");
}
catch (HttpRequestException a)
{
return View("Views/Landing/resetError.cshtml");
// return NotFound(a);
}
2018-12-12 15:17:08 +00:00
2019-04-06 21:17:49 +01:00
}
}
2019-04-06 00:37:03 +01:00
[HttpGet("/app")]
[AllowAnonymous]
public IActionResult appPage()
{
return View("Views/Landing/app.cshtml");
}
2019-04-06 21:17:49 +01:00
[HttpGet("/ctf")]
2019-04-06 00:37:03 +01:00
[AllowAnonymous]
2019-04-06 21:17:49 +01:00
public IActionResult ctfPage()
{
2019-04-06 00:37:03 +01:00
return View("Views/Landing/ctf.cshtml");
}
2019-04-08 20:18:51 +01:00
[AllowAnonymous]
2019-04-06 21:17:49 +01:00
[Route("{*url}", Order = 999)]
public IActionResult CatchAll()
{
Response.StatusCode = 404;
return View("Views/Landing/notFound.cshtml");
}
2018-12-12 15:17:08 +00:00
}
}