Commit 30c99d80 authored by Clouard Regis's avatar Clouard Regis
Browse files

Added image encrypt

parent 395a1748
......@@ -3,7 +3,7 @@
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
......@@ -12,19 +12,19 @@ class ChangeLocaleController extends AbstractController
/**
* @Route("/change_locale/{locale}", name="change_locale")
*/
public function changeLocale($locale, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse
public function changeLocale($locale, Request $request): RedirectResponse
{
$newUrl = explode('/',$request->headers->get('referer'));
$newUrl = explode('/', $request->headers->get('referer'));
$prefixToBeRemoved = ($request->getLocale() === "fr") ? 0 : 1;
if ($locale === "fr"){
array_splice($newUrl,3,$prefixToBeRemoved);
if ($locale === "fr") {
array_splice($newUrl, 3, $prefixToBeRemoved);
} else {
array_splice($newUrl,3,$prefixToBeRemoved,$locale);
array_splice($newUrl, 3, $prefixToBeRemoved, $locale);
}
$newUrl = implode("/",$newUrl);
$newUrl = implode("/", $newUrl);
return $this->redirect($newUrl);
}
......
......@@ -3,6 +3,7 @@
namespace App\Controller;
use App\Model\TrackStatistics;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
......@@ -18,6 +19,8 @@ use function simplexml_load_string;
class CourseController extends AbstractController
{
const MAX_DISTANCE_IN_METERS = 100_000;
/**
* @Route("/routes/{lat}-{lng}", name="course", requirements={"lat"="{\-?\d+(\.\d+)?}", "lng"="{\-?\d+(\.\d+)?}"}, defaults={"lat": 10000, "lng": 1000})
*/
......@@ -26,11 +29,11 @@ class CourseController extends AbstractController
$latitude = (float)substr($lat, 1, strlen($lat) - 2);
$longitude = (float)substr($lng, 1, strlen($lng) - 2);
$allCourses = $this->getDoctrine()->getRepository(Course::class)->findAll();
if ($lat < 10000 && $lng < 1000) {
if ($lat < 10000 && $lng < 1000) { // These are the default values...
$quantifiedCourses = [];
foreach ($allCourses as $course) {
$distance = $statistics->distanceInMeters($latitude, $longitude, $course->getLatitude(), $course->getLongitude());
if ($distance < 100_000) {
if ($distance < self::MAX_DISTANCE_IN_METERS) {
$quantifiedCourses[] = ["distance" => $distance, "course" => $course];
}
}
......@@ -51,10 +54,10 @@ class CourseController extends AbstractController
} else {
$courses = $allCourses;
}
foreach ($courses as $course){
foreach ($courses as $course) {
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
$dateDiff = $courseDate->diff(new DateTime('NOW'));
if ($dateDiff->invert === 1) {
unset($courses[array_search($course, $courses)]);
}
......@@ -77,7 +80,7 @@ class CourseController extends AbstractController
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
$dateDiff = $courseDate->diff(new DateTime('NOW'));
if ($dateDiff->invert === 1) {
return $this->render(
'course/notPublished.html.twig',
......@@ -91,8 +94,8 @@ class CourseController extends AbstractController
}
$importTab = 0;
$success = "";
if (!$course) {
throw $this->createNotFoundException("Ce parcours n'existe pas : " . $id);
if (!$course) { // TODO Warning
throw $this->createNotFoundException("Ce parcours n'existe pas : ".$id);
}
$xml = $course->getXml();
$simplexml = simplexml_load_string($xml);
......@@ -143,7 +146,7 @@ class CourseController extends AbstractController
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
$dateDiff = $courseDate->diff(new DateTime('NOW'));
if ($dateDiff->invert === 1) {
return $this->render(
'course/notPublished.html.twig',
......@@ -155,8 +158,8 @@ class CourseController extends AbstractController
);
}
}
if (!$course) {
throw $this->createNotFoundException('Ce parcours n\'existe pas : ' . $id);
if (!$course) { // TODO Test inutile puisque deka passer par $course-> getStartDate()
throw $this->createNotFoundException('Ce parcours n\'existe pas : '.$id);
}
$xml = $course->getXml();
$simplexml = simplexml_load_string($xml);
......@@ -190,7 +193,7 @@ class CourseController extends AbstractController
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if ($course == null) {
throw $this->createNotFoundException('Ce parcours n\'existe pas : ' . $id);
throw $this->createNotFoundException('Ce parcours n\'existe pas : '.$id);
}
return new JsonResponse(
......@@ -256,10 +259,10 @@ class CourseController extends AbstractController
public function worldMap(): Response
{
$courses = $this->getDoctrine()->getRepository(Course::class)->findAll();
foreach ($courses as $course){
foreach ($courses as $course) {
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
$dateDiff = $courseDate->diff(new DateTime('NOW'));
if ($dateDiff->invert === 1) {
unset($courses[array_search($course, $courses)]);
}
......
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210514132848 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE reset_password_request');
$this->addSql('ALTER TABLE course ADD club VARCHAR(30) DEFAULT NULL, CHANGE printable printable TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE track CHANGE imported imported TINYINT(1) NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE reset_password_request (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, selector VARCHAR(20) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, hashed_token VARCHAR(100) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, requested_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', expires_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_7CE748AA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('ALTER TABLE reset_password_request ADD CONSTRAINT FK_7CE748AA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON UPDATE NO ACTION ON DELETE NO ACTION');
$this->addSql('ALTER TABLE course DROP club, CHANGE printable printable TINYINT(1) DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE track CHANGE imported imported TINYINT(1) DEFAULT \'0\' NOT NULL');
}
}
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