Commit 19d6d889 authored by Clouard Regis's avatar Clouard Regis
Browse files

Before merge with current master.

parent 97efe195
......@@ -30,7 +30,8 @@
"symfony/validator": "5.0.*",
"symfony/web-link": "5.0.*",
"symfony/yaml": "5.0.*",
"ext-simplexml": "*"
"ext-simplexml": "*",
"ext-openssl": "*"
},
"require-dev": {
"dama/doctrine-test-bundle": "^6.3",
......
......@@ -107,7 +107,6 @@ function previewXml(xml, divXml) {
rowTitle.appendChild(titleName);
rowTitle.appendChild(titleType);
wideCol.appendChild(rowTitle);
//divXml.appendChild(rowTitle);
for (let [key, value] of Object.entries(xml)) {
let rowControl = document.createElement("div");
......@@ -121,7 +120,6 @@ function previewXml(xml, divXml) {
rowControl.appendChild(colName);
rowControl.appendChild(colType);
wideCol.appendChild(rowControl);
//divXml.appendChild(rowControl);
}
divXml.appendChild(wideCol);
}
......
......@@ -34,32 +34,32 @@ function removeTrack(event, map, gpx, track) {
event.target.addEventListener("click", handler);
}
function addTable(event, name, checkpoints) {
table.push([name, checkpoints]);
showTable();
function addTimeSheet(event, pseudo, checkpoints, gpxTrace) {
timeSheet.push([pseudo, checkpoints, gpxTrace]);
showTimeSheet();
let handler = function (e) {
e.target.removeEventListener("click", handler);
removeTable(e, name, checkpoints);
removeTimeSheet(e, pseudo, checkpoints, gpxTrace);
};
event.target.addEventListener("click", handler);
}
function removeTable(event, name, checkpoints) {
table.forEach(function (orienteer, index) {
if (orienteer[0] === name) {
table.splice(index, 1);
function removeTimeSheet(event, pseudo, checkpoints, gpxTrace) {
timeSheet.forEach(function (orienteer, index) {
if (orienteer[0] === pseudo) {
timeSheet.splice(index, 1);
}
});
showTable();
showTimeSheet();
let handler = function (e) {
e.target.removeEventListener("click", handler);
addTable(e, name, checkpoints);
addTimeSheet(e, pseudo, checkpoints, gpxTrace);
};
event.target.addEventListener("click", handler);
}
function renderTable() {
if (table.length === 0) {
function renderTimeSheet() {
if (timeSheet.length === 0) {
return document.createElement("p");
}
let elTable = document.createElement("table");
......@@ -68,18 +68,23 @@ function renderTable() {
let row = document.createElement("tr");
let name = document.createElement("th");
name.setAttribute("scope", "col");
name.innerHTML = "Balises";
name.innerHTML = "Poste";
row.appendChild(name);
head.appendChild(row);
let body = document.createElement("tbody");
let rows = [];
table[0][1].forEach(function (checkpoint, index) {
timeSheet[0][1].forEach(function (checkpoint, index) {
/*ll = L.LatLng(
el[i].getAttribute('lat'),
el[i].getAttribute('lon'));
ll.distanceTo()
*/
let row = document.createElement("tr");
let name = document.createElement("th");
name.setAttribute("scope", "col");
if (index === 0) {
name.innerHTML = "Départ";
} else if (index === table[0][1].length - 1) {
} else if (index === timeSheet[0][1].length - 1) {
name.innerHTML = "Arrivée";
} else {
name.innerHTML = index;
......@@ -89,7 +94,7 @@ function renderTable() {
rows.push(row);
});
table.forEach(function (orienteer) {
timeSheet.forEach(function (orienteer) {
let name = document.createElement("th");
name.setAttribute("scope", "col");
name.innerHTML = orienteer[0];
......@@ -110,8 +115,16 @@ function renderTable() {
let min = Math.floor(time / 1000 / 60);
let sec = Math.floor((time / 1000) % 60);
sec = sec.toString();
sec = (sec.length === 1 ? "0" + sec : sec); // TODO Meme chose que dans track.html.twig
sec = (sec.length === 1 ? "0" + sec : sec);
elCheckpoint.innerHTML = min + ":" + sec;
/* TODO
let seconds = Math.floor((orienteer[1] / 1000) % 60);
let minutes = Math.floor((orienteer[1] / (1000 * 60)) % 60);
let hours = Math.floor((orienteer[1] / (1000 * 60 * 60)) % 24);
seconds = (seconds < 10 ? "0" + seconds : seconds);
minutes = (minutes < 10 ? "0" + minutes : minutes);
trackButton.innerHTML = orienteer[0] + " " + hours + ":" + minutes + ":" + seconds;
*/
}
rows[index].appendChild(elCheckpoint);
});
......@@ -125,8 +138,8 @@ function renderTable() {
function addDownloadButton(event, pseudo, track, div) {
var button = document.createElement("button");
button.setAttribute('class', 'btn btn-primary');
button.innerHTML = " Télécharger " + pseudo + ".gpx";
button.style="display: block; margin-top: 5px; margin-bottom: 5px";
button.innerHTML = " " + pseudo + ".gpx";
button.style = "display: block; margin-top: 5px; margin-bottom: 5px";
var icon = document.createElement("span");
icon.className = "fa fa-download";
button.prepend(icon);
......
......@@ -18,55 +18,64 @@ class AdminController extends AbstractController
/**
* @Route("/admin/show_all", name="all_planners")
*/
public function show_all(){
public function show_all()
{
$users = $this->getDoctrine()->getRepository(User::class)->findAllPlanner();
return $this->render('admin/show_all.html.twig', [
'users' => $users,
]);
return $this->render(
'admin/show_all.html.twig',
[
'users' => $users,
]
);
}
/**
* @Route("/admin/delete_user/{id}", name="delete_user")
*/
public function delete(int $id){
public function delete(int $id)
{
$entityManager = $this->getDoctrine()->getManager();
$user = $this->getDoctrine()->getRepository(User::class)->find($id);
$user->remove($entityManager);
return $this->redirectToRoute('all_planners');
}
/**
* @Route("/admin/add_planner", name="add_planner")
*/
public function add_user(Request $request, TranslatorInterface $translator,
UserPasswordEncoderInterface $encoder, \Swift_Mailer $mailer){
public function add_user(Request $request, TranslatorInterface $translator, UserPasswordEncoderInterface $encoder, \Swift_Mailer $mailer)
{
$planner = new User();
$form = $this->createForm(PlannerType::class, $planner, ['password' => false]);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();
$creator = new CreateUser($user, $translator);
$valid = $creator->addUser($encoder, $this->getDoctrine()->getManager());
if($valid === true){
if ($valid === true) {
$creator->sendEmail($mailer, true);
return $this->redirectToRoute('all_planners');
}else{
return $this->render('admin/add_planner.html.twig', [
'form' => $form->createView(),
'error' => $valid,
]);
} else {
return $this->render(
'admin/add_planner.html.twig',
[
'form' => $form->createView(),
'error' => $valid,
]
);
}
}
return $this->render('admin/add_planner.html.twig', [
'form' => $form->createView(),
]);
return $this->render(
'admin/add_planner.html.twig',
[
'form' => $form->createView(),
]
);
}
}
......@@ -20,7 +20,7 @@ class ProfileController extends AbstractController
public function __construct(Security $security)
{
$this->security = $security;
$this->security = $security;
}
/**
......@@ -29,49 +29,53 @@ class ProfileController extends AbstractController
public function index(int $id)
{
$user = $this->security->getUser();
if($id != -1 && \in_array('ROLE_ADMIN', $user->getRoles())){
if ($id != -1 && \in_array('ROLE_ADMIN', $user->getRoles())) {
$user = $this->getDoctrine()->getRepository(User::class)->find($id);
}
return $this->render('profile/index.html.twig', [
'user' => $user,
]);
return $this->render(
'profile/index.html.twig',
[
'user' => $user,
]
);
}
/**
* @Route("/profile/modify", name="modify_info")
*/
public function modify(Request $request, TranslatorInterface $translator,
UserPasswordEncoderInterface $encoder){
public function modify(Request $request, TranslatorInterface $translator, UserPasswordEncoderInterface $encoder)
{
$planner = $this->security->getUser();
$form = $this->createForm(PlannerType::class, $planner, ['password' => true]);
if($request->request->get('password') == ""){
if ($request->request->get('password') == "") {
$_POST['password'] = $planner->getPassword();
$request = new Request($_POST);//if user don't change password generate weird bug
$request = new Request($_POST); // if user don't change password generates weird bug
}
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();
$creator = new CreateUser($user, $translator);
$valid = $creator->addUser($encoder, $this->getDoctrine()->getManager());
if($valid === true){
if ($valid === true) {
return $this->redirectToRoute('profile');
}else{
return $this->render('profile/modify.html.twig', [
'form' => $form->createView(),
'error' => $valid,
]);
} else {
return $this->render(
'profile/modify.html.twig',
[
'form' => $form->createView(),
'error' => $valid,
]
);
}
}
return $this->render('profile/modify.html.twig', [
'form' => $form->createView(),
]);
return $this->render(
'profile/modify.html.twig',
[
'form' => $form->createView(),
]
);
}
}
......@@ -63,10 +63,12 @@ class User implements UserInterface
public function isValid(): bool
{
$this->error = UserValidator::checkValid($this->username, $this->email);
return $this->error == UserValidator::$NO_ERR ? true : false;
}
public function remove(EntityManager $em){
public function remove(EntityManager $em)
{
foreach ($this->getCourses() as $course) {
$course->remove($em);
}
......@@ -92,7 +94,7 @@ class User implements UserInterface
*/
public function getUsername(): string
{
return (string) $this->username;
return (string)$this->username;
}
public function setUsername(string $username): self
......@@ -126,7 +128,7 @@ class User implements UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
return (string)$this->password;
}
public function setPassword(string $password): self
......@@ -155,11 +157,16 @@ class User implements UserInterface
public function getEmail(): ?string
{
/* $decrypted_email = openssl_decrypt($this->email, "AES-128-ECB", "1p*j&lmPqlvb"); TODO
voir https://symfony.com/doc/current/configuration/secrets.html
return $decrypted_email;*/
return $this->email;
}
public function setEmail(?string $email): self
{
/* $encrypted_string=openssl_encrypt($email,"AES-128-ECB","1p*j&lmPqlvb"); TODO
$this->email = $encrypted_string;*/
$this->email = $email;
return $this;
......
......@@ -27,7 +27,6 @@ class CreateUser
{
if ($this->user->getPassword() != "") {
$info = password_get_info($this->user->getPassword());
if ($info['algo'] == 0) {
if (strlen($this->user->getPassword()) < 4 || strlen($this->user->getPassword()) > 4095) {
return $this->translator->trans("password.invalid.must.be.more.than", ['number' => 4]);
......@@ -39,9 +38,7 @@ class CreateUser
$this->plainPassword = self::generatePassword();
$encoded = $encoder->encodePassword($this->user, $this->plainPassword);
}
$this->user->setPassword($encoded);
if (!$this->user->isValid()) {
return $this->translateError($this->user->getError());
} else {
......@@ -70,9 +67,7 @@ class CreateUser
{
$this->plainPassword = self::generatePassword();
$encoded = $encoder->encodePassword($this->user, $this->plainPassword);
$this->user->setPassword($encoded);
$em->persist($this->user);
$em->flush();
}
......
......@@ -74,7 +74,7 @@
<script>
var colorPicker = new ColorPicker();
let divLeaflet, map, overlay;
let table = [];
let timeSheet = [];
var tableEnable = false;
function showMap() {
......@@ -87,22 +87,21 @@
xhr.send()
}
function showTable() {
let divTable = document.getElementById("table");
function showTimeSheet() {
let divTable = document.getElementById("timeSheet");
while (divTable.lastElementChild) {
divTable.removeChild(divTable.lastElementChild);
}
divTable.appendChild(renderTable());
divTable.appendChild(renderTimeSheet());
}
window.addEventListener("load", function () {
divLeaflet = document.createElement("div");
map = generateMap(divLeaflet);
/* generateColorLegend(map);*/
overlay = L.imageOverlay.rotated("/none", L.latLng([-5, -5]), L.latLng([5, 5]), L.latLng([-5, 5]));
overlay.addTo(map);
showMap();
showTable();
showTimeSheet();
let xhr = new XMLHttpRequest();
xhr.open("GET", "{{ route_track }}");
xhr.onload = function () {
......@@ -110,35 +109,40 @@
let divTracks = document.getElementById("tracks");
if (data.tracks.length === 0) {
let trackButton = document.createElement("div");
trackButton.innerHTML = "Aucune trace GPS déposées.";
trackButton.innerHTML = "Aucune trace GPS déposée.";
divTracks.appendChild(trackButton);
} else {
data.tracks.forEach(function (orienteer) {
data.tracks.forEach(function (result) {
let pseudo = result[0];
let totalTimeInMs = result[1];
let gpxTrace = result[2];
let controlPoints = result[3];
let trackButton = document.createElement("button");
trackButton.className = "route";
let seconds = Math.floor((orienteer[1] / 1000) % 60);
let minutes = Math.floor((orienteer[1] / (1000 * 60)) % 60);
let hours = Math.floor((orienteer[1] / (1000 * 60 * 60)) % 24);
let seconds = Math.floor((totalTimeInMs / 1000) % 60);
let minutes = Math.floor((totalTimeInMs / (1000 * 60)) % 60);
let hours = Math.floor((totalTimeInMs / (1000 * 60 * 60)) % 24);
seconds = (seconds < 10 ? "0" + seconds : seconds);
minutes = (minutes < 10 ? "0" + minutes : minutes);
trackButton.innerHTML = orienteer[0] + " " + hours + ":" + minutes + ":" + seconds;
trackButton.innerHTML = pseudo + " " + hours + ":" + minutes + ":" + seconds;
divTracks.appendChild(trackButton);
let handler1 = function (e) {
e.target.removeEventListener("click", handler1);
addTrack(e, map, orienteer[2]);
addTrack(e, map, gpxTrace);
};
trackButton.addEventListener("click", handler1);
let handler2 = function (e) {
e.target.removeEventListener("click", handler2);
addTable(e, e.target.innerHTML, orienteer[3]);
addTimeSheet(e, e.target.innerHTML, controlPoints, gpxTrace);
};
trackButton.addEventListener("click", handler2);
let handler3 = function (e) {
e.target.removeEventListener("click", handler3);
addDownloadButton(e, e.target.innerHTML, orienteer[2], document.getElementById("Files"));
addDownloadButton(e, e.target.innerHTML, gpxTrace, document.getElementById("Files"));
};
trackButton.addEventListener("click", handler3);
});
......@@ -167,10 +171,10 @@
<!-- Tab content -->
<div id="Map" class="tabcontent">
<div id="map" style="min-width: 400px"></div>
<div id="map" style="min-width: 380px"></div>
</div>
<div id="Times" class="tabcontent">
<div id="table"></div>
<div id="timeSheet"></div>
</div>
<div id="Files" class="tabcontent">
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment