This commit is contained in:
parent
d30b355450
commit
ec89c33656
Binary file not shown.
|
@ -18,21 +18,25 @@ namespace api.Controllers
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class CromosController : ControllerBase
|
public class CromosController : ControllerBase
|
||||||
{
|
{ private readonly IUsersRepository _repo;
|
||||||
private readonly DataContext context;
|
private readonly DataContext context;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
public CromosController(DataContext context, IMapper mapper)
|
public CromosController(IUsersRepository repo,DataContext context, IMapper mapper)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
|
_repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/cromos/QR
|
// GET api/cromos/QR
|
||||||
// GET cromos do user QR
|
// GET cromos do user QR
|
||||||
|
|
||||||
[HttpGet("{QR}")]
|
[HttpGet("{QR}")]
|
||||||
|
|
||||||
public async Task<IActionResult> GetCromos(string QR)
|
public async Task<IActionResult> GetCromos(string QR)
|
||||||
{
|
{
|
||||||
int soma = 0;
|
int soma = 0;
|
||||||
|
int somaCTF=0;
|
||||||
var usr = await context.Users.FirstOrDefaultAsync(u => u.QRcode == QR);
|
var usr = await context.Users.FirstOrDefaultAsync(u => u.QRcode == QR);
|
||||||
string[] usrCromos = usr.cromos.Substring(1).Split(",");
|
string[] usrCromos = usr.cromos.Substring(1).Split(",");
|
||||||
Console.WriteLine(usrCromos[0]);
|
Console.WriteLine(usrCromos[0]);
|
||||||
|
@ -58,6 +62,9 @@ namespace api.Controllers
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(c.Id == 4 || c.Id==5 || c.Id==6 || c.Id==7 || c.Id==8 || c.Id==9 || c.Id==10 || c.Id==11 || c.Id==12 || c.Id==13 || c.Id==14 || c.Id==16){
|
||||||
|
somaCTF += c.pontos;
|
||||||
|
}
|
||||||
soma += c.pontos;
|
soma += c.pontos;
|
||||||
rList.Add(toAdd);
|
rList.Add(toAdd);
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -80,6 +87,17 @@ namespace api.Controllers
|
||||||
cromosToReturn a = new cromosToReturn();
|
cromosToReturn a = new cromosToReturn();
|
||||||
a.cromos = rList;
|
a.cromos = rList;
|
||||||
a.pontuacao = soma;
|
a.pontuacao = soma;
|
||||||
|
|
||||||
|
|
||||||
|
var userFromRepo = await _repo.GetUser(usr.Id);
|
||||||
|
|
||||||
|
userFromRepo.food = somaCTF;
|
||||||
|
userFromRepo.drinks = soma;
|
||||||
|
|
||||||
|
|
||||||
|
if (await _repo.SaveAll()){}
|
||||||
|
|
||||||
|
|
||||||
return Ok(a);
|
return Ok(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,8 @@ namespace api.Controllers
|
||||||
|
|
||||||
[Authorize(Policy = "RequireAdminRole")]
|
[Authorize(Policy = "RequireAdminRole")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|
||||||
|
//[AllowAnonymous]
|
||||||
public async Task<IActionResult> GetUsers()
|
public async Task<IActionResult> GetUsers()
|
||||||
{
|
{
|
||||||
var users = await _repo.GetUsers();
|
var users = await _repo.GetUsers();
|
||||||
|
|
|
@ -8,6 +8,8 @@ using api.Dtos;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using api.Models;
|
using api.Models;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using AutoMapper;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace api.Controllers
|
namespace api.Controllers
|
||||||
{
|
{
|
||||||
|
@ -15,13 +17,17 @@ namespace api.Controllers
|
||||||
[Route("/")]
|
[Route("/")]
|
||||||
public class mvcController : Controller
|
public class mvcController : Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private readonly IUsersRepository _repo;
|
||||||
private readonly DataContext _context;
|
private readonly DataContext _context;
|
||||||
private readonly UserManager<User> _userManager;
|
private readonly UserManager<User> _userManager;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
public mvcController(DataContext context, UserManager<User> userManager)
|
public mvcController(IUsersRepository repo, DataContext context, IMapper mapper, UserManager<User> userManager)
|
||||||
{
|
{
|
||||||
|
_mapper = mapper;
|
||||||
_context = context;
|
_context = context;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_repo = repo;
|
||||||
}
|
}
|
||||||
[HttpGet("/cp-ia")]
|
[HttpGet("/cp-ia")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
@ -67,6 +73,28 @@ namespace api.Controllers
|
||||||
return View("Views/Landing/jogo.cshtml");
|
return View("Views/Landing/jogo.cshtml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("/level1ctf")]
|
[HttpGet("/level1ctf")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult level1()
|
public IActionResult level1()
|
||||||
|
|
|
@ -61,8 +61,8 @@
|
||||||
<div class="ctf-header">
|
<div class="ctf-header">
|
||||||
<div class="ctf-top10">
|
<div class="ctf-top10">
|
||||||
<h1 class="top-title">Melhores classificados CTF </h1>
|
<h1 class="top-title">Melhores classificados CTF </h1>
|
||||||
<center><h3>Revelados em breve</h3></center>
|
|
||||||
|
<div id="content" class="table table-striped table-dark"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 class="about-top">Estas pontuações refletem o somatório das pontuações dos níveis cumpridos.</h3>
|
<h3 class="about-top">Estas pontuações refletem o somatório das pontuações dos níveis cumpridos.</h3>
|
||||||
|
@ -327,9 +327,80 @@
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const wrapper = document.getElementById('content');
|
||||||
|
|
||||||
|
|
||||||
|
const demoData = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
function fetchData() {
|
||||||
|
|
||||||
|
var top=[];
|
||||||
|
var i=1;
|
||||||
|
axios.get('http://localhost:5000/ctf/top')
|
||||||
|
.then(function (response) {
|
||||||
|
|
||||||
|
response.data.forEach(function(entry) {
|
||||||
|
top.push({Num:i, Nome: entry.nome, Pontos: entry.pontos})
|
||||||
|
i++
|
||||||
|
});
|
||||||
|
|
||||||
|
populate(top)
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
|
||||||
|
console.log(error);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', fetchData, false);
|
||||||
|
|
||||||
|
function dom(tag, text) {
|
||||||
|
let r = document.createElement(tag);
|
||||||
|
if (text) r.innerText = text;
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
|
||||||
|
function append(parent, child) {
|
||||||
|
parent.appendChild(child);
|
||||||
|
return parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
function populate(json) {
|
||||||
|
if (json.length === 0) return;
|
||||||
|
let keys = Object.keys(json[0]);
|
||||||
|
|
||||||
|
let table = dom('table');
|
||||||
|
|
||||||
|
append(table,
|
||||||
|
keys.map(k => dom('th', k)).reduce(append, dom('tr'))
|
||||||
|
);
|
||||||
|
|
||||||
|
const makeRow = (acc, row) =>
|
||||||
|
|
||||||
|
append(acc,
|
||||||
|
keys.map(k => dom('td', row[k])).reduce(append, dom('tr'))
|
||||||
|
);
|
||||||
|
|
||||||
|
json.reduce(makeRow, table);
|
||||||
|
wrapper.appendChild(table);
|
||||||
|
};
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
table{
|
||||||
|
width: 90%;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<!-- Scripts -->
|
<!-- Scripts -->
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/scripts.js"></script>
|
<script type="text/javascript" src="js/scripts.js"></script>
|
||||||
|
|
||||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
Loading…
Reference in New Issue