Skip to content

up #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Apr 25, 2025
Merged

up #346

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
56f70a3
Merge pull request #333 from marceloeatworld/antonin
marceloeatworld Oct 28, 2024
8a9f39c
Merge pull request #334 from marceloeatworld/main
marceloeatworld Oct 28, 2024
dce8dc4
Merge pull request #335 from marceloeatworld/marcelo
marceloeatworld Oct 28, 2024
83aae1d
Update MealController
tolgadev75 Dec 4, 2024
b6980be
Merge pull request #339 from marceloeatworld/tolgaV2
marceloeatworld Dec 13, 2024
09e6d4e
Create nixpacks.toml
marceloeatworld Apr 8, 2025
88f597d
Update nixpacks.toml
marceloeatworld Apr 8, 2025
b4ab32d
Update nixpacks.toml
marceloeatworld Apr 8, 2025
bf725a6
Update nixpacks.toml
marceloeatworld Apr 8, 2025
374d220
Update nixpacks.toml
marceloeatworld Apr 8, 2025
18fe55b
Update nixpacks.toml
marceloeatworld Apr 8, 2025
03b8d94
Update nixpacks.toml
marceloeatworld Apr 8, 2025
ecef282
Update nixpacks.toml
marceloeatworld Apr 8, 2025
260661e
Create nixpacks.toml
marceloeatworld Apr 9, 2025
f2e7305
Update nixpacks.toml
marceloeatworld Apr 9, 2025
6665ed4
Update nixpacks.toml
marceloeatworld Apr 9, 2025
51b0c3e
Update nixpacks.toml
marceloeatworld Apr 9, 2025
5d9a518
Update nixpacks.toml
marceloeatworld Apr 9, 2025
45a2e0f
Update AppServiceProvider.php
marceloeatworld Apr 9, 2025
9c96cc1
Update app.blade.php
marceloeatworld Apr 10, 2025
3d70073
Add Plunk email transport and service integration
marceloeatworld Apr 24, 2025
b5535ba
Fix permissions for Laravel storage in nixpacks.toml
marceloeatworld Apr 24, 2025
d91e1e6
Refactor worker-laravel command and reduce numprocs for better resour…
marceloeatworld Apr 24, 2025
79da69a
Refactor Plunk service registration and improve email sending logic
marceloeatworld Apr 24, 2025
4ce5553
Update PlunkService base URL to use the correct mail endpoint
marceloeatworld Apr 24, 2025
4a6017d
Update logo image for food equilibrium branding
marceloeatworld Apr 24, 2025
4222978
Refactor PlunkService to use configurable base URL and update email s…
marceloeatworld Apr 24, 2025
8508673
Refactor email sending logic in ContactController to simplify and sta…
marceloeatworld Apr 24, 2025
354de43
Enhance accessibility and SEO for navigation and meal generation pages
marceloeatworld Apr 24, 2025
1581892
Fix authentication response handling in AuthenticatedSessionControlle…
marceloeatworld Apr 24, 2025
03a768a
Refactor username handling in registration to ensure uniqueness by ap…
marceloeatworld Apr 24, 2025
f539023
Set default trusted proxies to '*' in TrustProxies middleware
marceloeatworld Apr 24, 2025
a912837
Update email verification route middleware to require authentication
marceloeatworld Apr 24, 2025
a0caa55
Merge pull request #342 from marceloeatworld/main
marceloeatworld Apr 24, 2025
ce131b7
Merge pull request #343 from marceloeatworld/marcelo
marceloeatworld Apr 24, 2025
88dcbaa
chore: update dependencies in package-lock.json
marceloeatworld Apr 24, 2025
0947ed4
Refactor code structure for improved readability and maintainability
marceloeatworld Apr 25, 2025
53ffce4
fix: remove unnecessary space in image source path in README.md
marceloeatworld Apr 25, 2025
4768d29
Merge pull request #344 from marceloeatworld/main
marceloeatworld Apr 25, 2025
572322f
Merge pull request #345 from marceloeatworld/marcelo
marceloeatworld Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public function create(): View
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();

$request->session()->regenerate();
return $request->authenticate();
// return redirect()->intended(RouteServiceProvider::HOME);
return redirect()->intended(RouteServiceProvider::HOME);
}

/**
Expand Down
21 changes: 16 additions & 5 deletions InstaRepas/app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,29 @@ public function store(Request $request): RedirectResponse
'email' => ['required', 'string', 'max:255', 'unique:'.User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);


// Vérifier si le nom d'utilisateur existe déjà
$baseUsername = $request->username;
$username = $baseUsername;
$counter = 1;

// Ajouter un suffixe numérique si le nom d'utilisateur existe déjà
while (User::where('username', $username)->exists()) {
$username = $baseUsername . $counter;
$counter++;
}

$user = User::create([
'username' => $request->username,
'username' => $username, // Utiliser le nom d'utilisateur potentiellement modifié
'email' => $request->email,
'password' => Hash::make($request->password),
'registration_date' => now(),
]);

event(new Registered($user));

Auth::login($user);

return redirect(RouteServiceProvider::HOME);
}
}
36 changes: 18 additions & 18 deletions InstaRepas/app/Http/Controllers/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ public function submit(Request $request)
$details = [
'name' => $request->name,
'email' => $request->email,
'subject' => $request->subject,
'subject' => $this->getSubjectText($request->subject),
'message' => $request->message,
];

// send email
if ($request->subject == 'technical_problem') {
Mail::to([
env('TECH_SUPPORT_EMAIL_1', '[email protected]'),
env('TECH_SUPPORT_EMAIL_2', '[email protected]')
])->send(new ContactMail($details));
} else {
Mail::to([
env('FIRST_EMAIL', '[email protected]'),
env('SECOND_EMAIL', '[email protected]')
])->send(new ContactMail($details));
}
// Envoi de l'email à [email protected] pour tous les cas
Mail::to('[email protected]')->send(new ContactMail($details));



// redirect with success message
// Redirection avec message de succès
return redirect()->back()->with('success', 'Votre message a été envoyé avec succès.');

}

}
/**
* Convertit le code du sujet en texte lisible
*/
private function getSubjectText($subject)
{
$subjects = [
'technical_problem' => 'Problème technique',
'information' => 'Demande d\'information',
'suggestion' => 'Suggestion',
];

return $subjects[$subject] ?? $subject;
}
}
85 changes: 71 additions & 14 deletions InstaRepas/app/Http/Controllers/MealController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
class MealController extends Controller
{
private $restrictions = [];
private $meatCount = 0;
private $lastReset = 0;
private $dayCount = 0;
private $lastMeatDay = -1;
private $usedMeats = [];

// Méthode pour générer des repas
public function generate(Request $request)
{
$this->meatCount = 0;
$this->lastReset = 0;
$this->dayCount = 0;
// Récupération des restrictions àN partir de la requête
$this->restrictions = $request->input('restrictions', []);
$include_snacks = $request->input('include_snacks', false);
Expand All @@ -31,7 +39,9 @@ public function generate(Request $request)
$availableDietaryRestrictions = DietaryRestriction::all();

// Création de la requête pour récupérer les aliments
$foods = Food::query();
// $foods = Food::query();
$foods = Food::with('category')->where('is_valid', true);


// Filtrage des aliments en fonction des restrictions
foreach ($this->restrictions as $restriction) {
Expand All @@ -51,7 +61,7 @@ public function generate(Request $request)
}

// Ajout de la vérification des aliments validés
$foods->where('is_valid', true);
// $foods->where('is_valid', operator: true);

$foods = $foods->get();

Expand Down Expand Up @@ -156,31 +166,78 @@ private function generateBreakfast($foods)
// Cette fonction génère un déjeuner ou un dîner en fonction des aliments disponibles.
private function generateLunchOrDinner($foods)
{
// Récupère un aliment contenant des protéines.
// Si l'utilisateur a une restriction alimentaire qui interdit les produits animaux, sélectionne une protéine végétale.
$proteinCategory = in_array('contains_animal_products', $this->restrictions) ? 'Legumes' : ['Meat', 'Fish', 'Eggs', 'Pork'];
$proteinFood = $foods->whereIn('category.name', $proteinCategory)->count() > 0 ? $foods->whereIn('category.name', $proteinCategory)->random() : null;
// Variables pour le suivi des jours et de la viande
$currentDay = floor($this->dayCount / 2); // On divise par 2 pour gérer déjeuner/dîner

// Réinitialisation hebdomadaire
if (floor($currentDay / 7) > $this->lastReset) {
$this->meatCount = 0;
$this->usedMeats = [];
$this->lastReset = floor($currentDay / 7);
}

// Détection des limites de viande
$isMaxMeatWeek = $this->meatCount >= 3; // Max 3 repas avec viande par semaine
$isSameDayMeat = $currentDay === $this->lastMeatDay; // Pas deux repas viande le même jour
$isMaxMeat = $isMaxMeatWeek || $isSameDayMeat;

// Détermination des catégories de protéines
$proteinCategory = $isMaxMeat ?
['Fish', 'Eggs', 'Legumes'] : // Alternatives si viande non autorisée
(in_array('contains_animal_products', $this->restrictions) ?
'Legumes' : // Protéines végétales si produit animal interdit
['Meat', 'Fish', 'Eggs', 'Pork'] // Protéines classiques
);

// Sélection de la protéine
$proteinFood = $foods->whereIn('category.name', $proteinCategory)
->whereNotIn('id', $this->usedMeats) // Évite les doublons
->count() > 0 ? $foods->whereIn('category.name', $proteinCategory)
->whereNotIn('id', $this->usedMeats)
->random() : null;

// Mise à jour des compteurs si un aliment de viande est utilisé
if ($proteinFood && $proteinFood->category && in_array($proteinFood->category->name, ['Meat', 'Pork'])) {
$this->meatCount++;
$this->lastMeatDay = $currentDay;
$this->usedMeats[] = $proteinFood->id;
}

// Gestion des glucides et fibres en fonction des restrictions
$carbohydrateFood = null;
$fiberFood = null;

// Si l'utilisateur a une restriction alimentaire qui interdit les produits animaux, sélectionne des aliments riches en glucides et en fibres.
// Si l'utilisateur a une restriction alimentaire qui interdit les produits animaux
if (in_array('contains_animal_products', $this->restrictions)) {
$carbohydrateFood = $foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->count() > 0 ? $foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->random() : null;
$fiberFood = $foods->where('category.name', 'Vegetables')->where('nutritional_type', 'fibers')->count() > 0 ? $foods->where('category.name', 'Vegetables')->where('nutritional_type', 'fibers')->random() : null;
$carbohydrateFood = $foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->count() > 0
? $foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->random()
: null;
$fiberFood = $foods->where('category.name', 'Vegetables')->where('nutritional_type', 'fibers')->count() > 0
? $foods->where('category.name', 'Vegetables')->where('nutritional_type', 'fibers')->random()
: null;
}

// Incrémentation du compteur global de jours
$this->dayCount++;

return [
'protein' => $proteinFood,

'carbohydrate' => in_array('contains_animal_products', $this->restrictions) ? $carbohydrateFood : ($foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->count() > 0 ? $foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->random() : null),
'carbohydrate' => in_array('contains_animal_products', $this->restrictions)
? $carbohydrateFood
: ($foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->count() > 0
? $foods->where('category.name', 'Grains')->where('nutritional_type', 'carbohydrates')->random()
: null),
'fiber' => in_array('contains_animal_products', $this->restrictions) ? $fiberFood : null,
'vegetable' => $foods->where('category.name', 'Vegetables')->count() > 0 ? $foods->where('category.name', 'Vegetables')->random() : null,
'lipid' => $foods->where('category.name', 'Oils')->count() > 0 ? $foods->where('category.name', 'Oils')->random() : null,
'vegetable' => $foods->where('category.name', 'Vegetables')->count() > 0
? $foods->where('category.name', 'Vegetables')->random()
: null,
'lipid' => $foods->where('category.name', 'Oils')->count() > 0
? $foods->where('category.name', 'Oils')->random()
: null,
];

}


// Cette fonction génère un snack en fonction des aliments disponibles.
private function generateSnack($foods)
{
Expand Down
3 changes: 2 additions & 1 deletion InstaRepas/app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class TrustProxies extends Middleware
*
* @var array<int, string>|string|null
*/
protected $proxies;
// Dans App\Http\Middleware\TrustProxies.php
protected $proxies = '*';

/**
* The headers that should be used to detect proxies.
Expand Down
3 changes: 3 additions & 0 deletions InstaRepas/app/Http/Middleware/ValidateSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ class ValidateSignature extends Middleware
// 'utm_medium',
// 'utm_source',
// 'utm_term',
'*',
'expires',
'signature',
];
}
94 changes: 94 additions & 0 deletions InstaRepas/app/Mail/Transport/PlunkTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Mail\Transport;

use App\Services\PlunkService;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\MessageConverter;

class PlunkTransport extends AbstractTransport
{
protected $plunkService;

public function __construct(PlunkService $plunkService)
{
parent::__construct();
$this->plunkService = $plunkService;
}

protected function doSend(SentMessage $message): void
{
// Convertir le message Symfony en Email
$email = MessageConverter::toEmail($message->getOriginalMessage());

// Extraire les destinataires
$to = array_map(function (Address $address) {
return $address->getAddress();
}, $email->getTo());

// Si un seul destinataire, le transformer en string plutôt qu'un tableau
$to = count($to) === 1 ? $to[0] : $to;

// Extraire l'expéditeur
$fromAddresses = $email->getFrom();
$from = null;
$name = null;

if (count($fromAddresses) > 0) {
$fromAddress = $fromAddresses[0];
$from = $fromAddress->getAddress();
$name = $fromAddress->getName();
}

// Extraire l'adresse de réponse
$replyToAddresses = $email->getReplyTo();
$replyTo = null;

if (count($replyToAddresses) > 0) {
$replyToAddress = $replyToAddresses[0];
$replyTo = $replyToAddress->getAddress();
}

// Extraire les en-têtes personnalisés
$headers = [];
foreach ($email->getHeaders()->all() as $header) {
// Ignorer certains en-têtes standard
if (!in_array(strtolower($header->getName()), ['from', 'to', 'subject', 'cc', 'bcc'])) {
$headers[$header->getName()] = $header->getBodyAsString();
}
}

// Préparer les options pour Plunk
$options = [];
if ($from) $options['from'] = $from;
if ($name) $options['name'] = $name;
if ($replyTo) $options['reply'] = $replyTo;
if (!empty($headers)) $options['headers'] = $headers;

// Déterminer le corps du message (HTML ou texte)
$body = $email->getHtmlBody();
if (empty($body)) {
$body = $email->getTextBody();
}

// Envoyer l'email via le service Plunk
$result = $this->plunkService->sendEmail(
$to,
$email->getSubject(),
$body,
$options
);

// Si l'envoi échoue, générer une exception
if (isset($result['success']) && $result['success'] === false) {
throw new \RuntimeException('Erreur lors de l\'envoi via Plunk: ' . ($result['error'] ?? 'Erreur inconnue'));
}
}

public function __toString(): string
{
return 'plunk';
}
}
19 changes: 16 additions & 3 deletions InstaRepas/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Providers;

use App\Mail\Transport\PlunkTransport;
use App\Services\PlunkService;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -11,14 +15,23 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
//
$this->app->singleton(PlunkService::class, function ($app) {
return new PlunkService();
});
}

/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
if (config('app.env') === 'production') {
URL::forceScheme('https');
}

// Corriger l'enregistrement du transport Plunk
Mail::extend('plunk', function ($config) {
return new PlunkTransport(app(PlunkService::class));
});
}
}
}
Loading