Compare commits
4 Commits
master
...
issue_031_
Author | SHA1 | Date |
---|---|---|
David D'ALMEIDA | 9eb7074df5 | 11 months ago |
David D'ALMEIDA | adb9584cba | 12 months ago |
Antoine PINAGOT | d0d1d4c23d | 12 months ago |
David D'ALMEIDA | f804820e85 | 12 months ago |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 2.0 MiB |
@ -1,36 +1,95 @@
|
||||
<?php
|
||||
|
||||
// namespace App\Controller;
|
||||
|
||||
// use App\Container;
|
||||
// use App\Router\Request\IRequest;
|
||||
// use App\Router\Response\Response;
|
||||
// use Shared\Attributes\Route;
|
||||
// use Twig\Environment;
|
||||
// use Data\Core\Preferences;
|
||||
// use Shared\Log;
|
||||
|
||||
// class HeartRateController extends BaseController
|
||||
// {
|
||||
|
||||
|
||||
// #[Route(path: '/import', name: 'import', methods: ['GET'])]
|
||||
// public function import(): Response
|
||||
// {
|
||||
// return $this->render('./page/import.html.twig',[
|
||||
// 'css' => $this->preference->getCookie(),
|
||||
// 'pp' => "test2",
|
||||
// 'user' => "Doe",
|
||||
// 'role' => "Athlète",
|
||||
// 'friendship' => [],
|
||||
// 'analyzes' => [],
|
||||
// 'mails' => [],
|
||||
// 'users' => [],
|
||||
// 'infoUser' => [],
|
||||
// 'exos' => [],
|
||||
// 'member' => []
|
||||
// ]);
|
||||
// }
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Container;
|
||||
use App\Router\Request\IRequest;
|
||||
use App\Router\Response\IResponse;
|
||||
use App\Router\Response\RedirectResponse;
|
||||
use App\Router\Response\Response;
|
||||
use Manager\ActivityManager;
|
||||
use Shared\Attributes\Route;
|
||||
use Twig\Environment;
|
||||
use Data\Core\Preferences;
|
||||
use Shared\Log;
|
||||
|
||||
class HeartRateController extends BaseController
|
||||
{
|
||||
|
||||
private ActivityManager $activityMgr;
|
||||
|
||||
public function __construct(ActivityManager $manager)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->activityMgr = $manager;
|
||||
}
|
||||
|
||||
#[Route(path: '/import', name: 'import', methods: ['GET'])]
|
||||
public function import(): Response
|
||||
{
|
||||
return $this->render('./page/import.html.twig', [
|
||||
'css' => $this->preference->getCookie(),
|
||||
'pp' => "test2",
|
||||
'user' => "Doe",
|
||||
'role' => "Athlète",
|
||||
'friendship' => [],
|
||||
'analyzes' => [],
|
||||
'mails' => [],
|
||||
'users' => [],
|
||||
'infoUser' => [],
|
||||
'exos' => [],
|
||||
'member' => []
|
||||
]);
|
||||
}
|
||||
|
||||
// }
|
||||
#[Route(path: '/upload', name: 'upload', methods: ['POST'])]
|
||||
public function uploadFile(string $activityType, int $effort, IRequest $req): IResponse
|
||||
{
|
||||
$error = $this->validateRequest($effort);
|
||||
if (!empty($error)) {
|
||||
return $this->renderError($error);
|
||||
}
|
||||
|
||||
$tmp_file = $_FILES['uploaded_file']['tmp_name'];
|
||||
if (!$this->isValidFile($tmp_file)) {
|
||||
return $this->renderError(['Failed to get file be sure that you provide the file']);
|
||||
}
|
||||
|
||||
$content = file_get_contents($tmp_file);
|
||||
try {
|
||||
|
||||
if ($this->activityMgr->uploadFile($activityType, 5, $content)) {
|
||||
return new RedirectResponse('/');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->renderError([$e->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->renderError(['Failed to save activity.']);
|
||||
}
|
||||
|
||||
private function validateRequest(int $effort): array
|
||||
{
|
||||
$error = [];
|
||||
if ($effort < 0 || $effort > 5) {
|
||||
$error[] = 'Invalid effort level.';
|
||||
}
|
||||
$fileExtension = pathinfo($_FILES['uploaded_file']['name'], PATHINFO_EXTENSION);
|
||||
if ($fileExtension !== 'fit') {
|
||||
$error[] = 'Invalid file type. Only .fit files are allowed.';
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
|
||||
private function isValidFile(string $tmp_file): bool
|
||||
{
|
||||
return file_exists($tmp_file) && is_uploaded_file($tmp_file);
|
||||
}
|
||||
|
||||
private function renderError(array $error): Response
|
||||
{
|
||||
// Consolidez la logique de rendu ici
|
||||
return $this->render('./error/error.html.twig', ['title'=> "Failed" , "code" => 400, "name" => "error import", "descr" => $error[0] ], new Response('$error', 400));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<a href="/log">Se connecter</button>
|
@ -1,40 +1,48 @@
|
||||
{% extends "authbase.html.twig" %}
|
||||
|
||||
{% block css %}{{css}}{% endblock %}
|
||||
{% block css %}{{ css }}{% endblock %}
|
||||
|
||||
{% block title %}Connexion - HearthTrack{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="card shadow-lg border-0 rounded-lg mt-5">
|
||||
<div class="card-header"><h3 class="text-center font-weight-light my-4">Connexion</h3></div>
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="inputEmail" type="email" placeholder="nom@exemple.com" />
|
||||
<label for="inputEmail">Adresse eMail</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="inputPassword" type="password" placeholder="Mot de passe" />
|
||||
<label for="inputPassword">Mot de passe</label>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" id="inputRememberPassword" type="checkbox" value="" />
|
||||
<label class="form-check-label" for="inputRememberPassword">Mémoriser le mot de passe</label>
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
|
||||
<a class="small" href="password.html">Mot de passe oublié ?</a>
|
||||
<a class="btn btn-primary" href="index.html">Se connecter</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center py-3">
|
||||
<div class="small"><a href="register.html">Besoin d'un compte ? Inscrivez-vous !</a></div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="card shadow-lg border-0 rounded-lg mt-5">
|
||||
<div class="card-header"><h3 class="text-center font-weight-light my-4">Connexion</h3></div>
|
||||
<div class="card-body">
|
||||
{% if login_error %}
|
||||
{% for value in login_error %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ value }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="/login">
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="email" name="email" type="text" placeholder="Nom d'utilisateur" />
|
||||
<label for="email">Nom d'utilisateur</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="password" name="password" type="password" placeholder="Mot de passe" />
|
||||
<label for="password">Mot de passe</label>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" id="inputRememberPassword" type="checkbox" value="" />
|
||||
<label class="form-check-label" for="inputRememberPassword">Mémoriser le mot de passe</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
|
||||
<a class="small" href="/forgetPassword">Mot de passe oublié ?</a>
|
||||
<button class="btn btn-primary" type="submit">Se connecter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center py-3">
|
||||
<div class="small"><a href="/register">Besoin d'un compte ? Inscrivez-vous !</a></div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -0,0 +1,33 @@
|
||||
{% extends "authbase.html.twig" %}
|
||||
|
||||
{% block css %}{{css}}{% endblock %}
|
||||
|
||||
{% block title %}Mot de passe oublié - HearthTrack{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="card shadow-lg border-0 rounded-lg mt-5">
|
||||
<div class="card-header"><h3 class="text-center font-weight-light my-4">Récupération du mot de passe</h3></div>
|
||||
<div class="card-body">
|
||||
<div class="small mb-3 text-muted">Entrez votre adresse eMail pour recevoir un lien pour changer de mot de passe</div>
|
||||
<form method="post" action="/">
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="email" name="email" type="email" placeholder="name@example.com" />
|
||||
<label for="email">Adresse eMail</label>
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
|
||||
<a class="small" href="/login">Retour à la connexion</a>
|
||||
<button class="btn btn-primary" type="submit">Réinitialiser votre mot de passe</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center py-3">
|
||||
<div class="small"><a href="/register">Besoin d'un compte ? Inscrivez-vous !</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in new issue