Skip to content
Snippets Groups Projects
Commit 4f40a9c0 authored by Gabriel Frey's avatar Gabriel Frey
Browse files

Ajout correction TP 10

parent 51b4c190
Branches
No related merge requests found
Showing
with 8698 additions and 0 deletions
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[docker-compose.yml]
indent_size = 4
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database
PHP_CLI_SERVER_WORKERS=4
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
CACHE_STORE=database
CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
* text=auto eol=lf
*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/pail
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.nova
/.vscode
/.zed
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
## About Laravel
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
Laravel is accessible, powerful, and provides tools required for large, robust applications.
## Learning Laravel
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
## Laravel Sponsors
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
### Premium Partners
- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[WebReinvent](https://webreinvent.com/)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
- **[Jump24](https://jump24.co.uk)**
- **[Redberry](https://redberry.international/laravel/)**
- **[Active Logic](https://activelogic.com)**
- **[byte5](https://byte5.de)**
- **[OP.GG](https://op.gg)**
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Memo;
use App\Models\UserEloquent;
class MemoController extends Controller
{
/**
* Show the required memo
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function show( Request $request, int $id )
{
return view('memo')
->with('memo',Memo::findOrFail($id))
->with('message',$request->session()->get('message'));
}
/**
* Show the three last memos
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function last( Request $request )
{
$lastMemos = Memo::where('public',true)
->orderBy('published_on','desc')
->take(3)
->get();
return view('home')
->with('memos',$lastMemos)
->with('message',$request->session()->get('message'));
}
/**
* Show the form to write a new memo
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function formMemo( Request $request )
{
return view('addmemo')
->with('message',$request->session()->get('message'));
}
/**
* Show the form to edit an memo
*
* @param \Illuminate\Http\Request $request
* @param int $memo_id
* @return \Illuminate\Http\Response
*/
public function formeditmemo( Request $request, int $memo_id )
{
return view('memoedit')
->with('memo',Memo::find($memo_id))
->with('message',$request->session()->get('message'));
}
/**
* Add a new memo
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function add( Request $request )
{
if ( !$request->filled(['title', 'content']) )
return to_route('view_formmemo')->with('message','Some POST data are missing.');
$memo = new Memo;
$memo->owner= $request->session()->get('user')->login;
$memo->title = $request->title;
$memo->content = $request->content;
$memo->public = (bool) $request->public;
$memo->published_on = $memo->public ? now() : null;
$memo->last_update = $memo->published_on;
try
{
$memo->save();
}
catch (\Illuminate\Database\QueryException $e)
{
return to_route('view_formmemo')
->with('message','Sorry, an error occur durng memo saving. Please try again : ' . $e);
}
return to_route('view_account')->with('message','New memo created!');
}
/**
* Chnage the publication status on/off
*
* @param \Illuminate\Http\Request $request
* @param int $memo_id
* @return \Illuminate\Http\Response
*/
public function toggleStatus( Request $request, int $memo_id )
{
$currentDate= now();
$memo = Memo::find($memo_id);
if ( $memo->public)
{
$memo->public = false;
$memo->published_on = null;
}
else
{
$memo->public = true;
$memo->published_on = $currentDate;
}
try
{
$memo->save();
}
catch (\Illuminate\Database\QueryException $e)
{
return to_route('view_memo_list')
->with('message','Sorry, an error occur durng memo update. Please try again.');
}
return to_route('view_memo_list');
}
/**
* Edit an memo
*
* @param \Illuminate\Http\Request $request
* @param int $memo_id
* @return \Illuminate\Http\Response
*/
public function edit( Request $request, int $memo_id )
{
if ( !$request->filled(['title','content']) )
return to_route('view_memo_list')->with('message','Some POST data are missing.');
$memo = Memo::find($memo_id);
$memo->title = $request->title;
$memo->content = $request->content;
$memo->last_update = now();
try
{
$memo->save();
}
catch (\Illuminate\Database\QueryException $e)
{
return to_route('view_memo_list')
->with('message','Sorry, an error occur during memo saving. Please try again.');
}
return to_route('view_memo_list')->with('message','Memo updated!');
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Models\MyUser;
class UserController extends Controller
{
/**
* Signout
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function disconnect( Request $request )
{
$request->session()->flush();
return to_route('view_home');
}
/**
* Authentication
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function connect( Request $request )
{
if ( !$request->filled(['login','password']) )
return to_route('view_signin')->with('message','Some POST data are missing.');
try
{
$user = MyUser::where('login',$request->login)->firstOrFail();
}
catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e)
{
return to_route('view_signin')->with('message','Wrong login.');
}
if ( !Hash::check($request->password,$user->password) )
return to_route('view_signin')->with('message','Wrong password.');
$request->session()->put('user',$user);
return to_route('view_account');
}
/**
* Add a user
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function create( Request $request )
{
if ( !$request->filled(['login','password','confirm']) )
return to_route('view_signup')->with('message','Some POST data are missing.');
if ( $request->password !== $request->confirm )
return to_route('view_signup')->with('message','Error: the two passwords differ. Try again.');
$user = new MyUser;
$user->login = $request->login;
$user->password = Hash::make($request->password);
try
{
$user->save();
}
catch (\Illuminate\Database\QueryException $e)
{
return to_route('view_signup')
->with('message','Sorry, this login still exists. Please choose another one.');
}
return to_route('view_signin')->with('message','Account created! Now, signin.');
}
/**
* Change the user password
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function updatePassword( Request $request )
{
if ( !$request->filled(['newpassword','confirmpassword']) )
return to_route('view_formpassword')->with('message','Some POST data are missing.');
if ( $request->newpassword != $request->confirmpassword )
return to_route('view_formpassword')->with('message','Error: the two passwords differ. Try again.');
try
{
$user = $request->session()->get('user');
$user->password = Hash::make($request->newpassword);
$user->save();
}
catch (\Illuminate\Database\QueryException $e)
{
return to_route('view_formpassword')->with('message','Error: password changing failed. Try again.');
}
return to_route('view_account')->with('message','Password successfully updated.');
}
/**
* Delete the logged user
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function delete( Request $request )
{
try
{
$request->session()->get('user')->delete();
}
catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e)
{
return to_route('view_account')->with('message','Error during deletion. Try again.');
}
$request->session()->flush();
return to_route('view_signin')->with('message','Account successfully deleted.');
}
}
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class AuthenticateMyUser
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ( $request->session()->missing('user') )
return to_route('view_home');
$request->user = $request->session()->get('user');
return $next($request);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Memo extends Model
{
protected $table = 'memos';
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class MyUser extends Model {
public $timestamps = false;
protected $table = 'myusers';
protected $primaryKey = 'login';
protected $keyType = 'string';
public function memos(): HasMany
{
return $this->hasMany(Memo::class,'owner');
}
}
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Input\ArgvInput;
define('LARAVEL_START', microtime(true));
// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';
// Bootstrap Laravel and handle the command...
$status = (require_once __DIR__.'/bootstrap/app.php')
->handleCommand(new ArgvInput);
exit($status);
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
*
!.gitignore
<?php
return [
App\Providers\AppServiceProvider::class,
];
{
"$schema": "https://getcomposer.org/schema.json",
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"require": {
"php": "^8.2",
"laravel/framework": "^11.31",
"laravel/tinker": "^2.9"
},
"require-dev": {
"fakerphp/faker": "^1.23",
"laravel/pail": "^1.1",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.1",
"phpunit/phpunit": "^11.0.1"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
"@php artisan migrate --graceful --ansi"
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
This diff is collapsed.
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application, which will be used when the
| framework needs to place the application's name in a notification or
| other UI elements where an application name needs to be displayed.
|
*/
'name' => env('APP_NAME', 'Laravel'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services the application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => (bool) env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| the application so that it's available within Artisan commands.
|
*/
'url' => env('APP_URL', 'http://localhost'),
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. The timezone
| is set to "UTC" by default as it is suitable for most use cases.
|
*/
'timezone' => env('APP_TIMEZONE', 'UTC'),
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by Laravel's translation / localization methods. This option can be
| set to any locale for which you plan to have translation strings.
|
*/
'locale' => env('APP_LOCALE', 'en'),
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is utilized by Laravel's encryption services and should be set
| to a random, 32 character string to ensure that all encrypted values
| are secure. You should do this prior to deploying the application.
|
*/
'cipher' => 'AES-256-CBC',
'key' => env('APP_KEY'),
'previous_keys' => [
...array_filter(
explode(',', env('APP_PREVIOUS_KEYS', ''))
),
],
/*
|--------------------------------------------------------------------------
| Maintenance Mode Driver
|--------------------------------------------------------------------------
|
| These configuration options determine the driver used to determine and
| manage Laravel's "maintenance mode" status. The "cache" driver will
| allow maintenance mode to be controlled across multiple machines.
|
| Supported drivers: "file", "cache"
|
*/
'maintenance' => [
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
'store' => env('APP_MAINTENANCE_STORE', 'database'),
],
];
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