diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php new file mode 100644 index 0000000..dc57a37 --- /dev/null +++ b/app/Http/Controllers/ProfileController.php @@ -0,0 +1,81 @@ +check ()) { + return redirect ()->route ("login"); + } + + $user = auth ()->user (); + + return view ("users.edit", compact ("user")); + } + + public function update (Request $request) + { + if (!auth ()->check ()) { + return redirect ()->route ("login"); + } + + $incoming_fields = $request->validate ([ + "avatar" => "image|max:4096", + "bio" => "sometimes|nullable|string", + "general" => "sometimes|nullable|string", + "music" => "sometimes|nullable|string", + "movies" => "sometimes|nullable|string", + "television" => "sometimes|nullable|string", + "books" => "sometimes|nullable|string", + "heroes" => "sometimes|nullable|string" + ]); + + $user = auth ()->user (); + $fname = $user->id . "-" . uniqid () . ".jpg"; + + $changing_avatar = false; + if (isset ($incoming_fields["avatar"]) && !empty ($incoming_fields["avatar"])) + { + $manager = new ImageManager (new Driver ()); + $image = $manager->read ($request->file ("avatar")); + $image_data = $image->cover (256, 256)->toJpeg (); + Storage::disk ("public")->put ("avatars/" . $fname, $image_data); + + $old_avatar = $user->avatar; + $user->avatar = $fname; + + $changing_avatar = true; + } + + $user->bio = $incoming_fields["bio"]; + $user->interests_general = $incoming_fields["general"]; + $user->interests_music = $incoming_fields["music"]; + $user->interests_movies = $incoming_fields["movies"]; + $user->interests_television = $incoming_fields["television"]; + $user->interests_books = $incoming_fields["books"]; + $user->interests_heroes = $incoming_fields["heroes"]; + $user->save (); + + if ($changing_avatar) + { + Storage::disk ("public")->delete (str_replace ("/storage/", "", $old_avatar)); + } + + return back ()->with ("success", "Profile updated successfully!"); + } +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f910167..03dca85 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -55,9 +55,4 @@ class UserController extends Controller return redirect ()->route ("login")->with ("success", "You have successfuly logged out!"); } - - public function show (User $user) - { - return view ("users.profile", compact ("user")); - } } diff --git a/composer.json b/composer.json index 60681e6..645174e 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "license": "MIT", "require": { "php": "^8.2", + "intervention/image": "^3.10", "laravel/framework": "^11.31", "laravel/tinker": "^2.9" }, diff --git a/composer.lock b/composer.lock index f543f13..d9db450 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "626b9e7ddd47fb7eff9aaa53cce0c9ad", + "content-hash": "64b78dd438697d218ce81a8ea6afcbb3", "packages": [ { "name": "brick/math", @@ -1054,6 +1054,150 @@ ], "time": "2023-12-03T19:50:20+00:00" }, + { + "name": "intervention/gif", + "version": "4.2.0", + "source": { + "type": "git", + "url": "https://github.com/Intervention/gif.git", + "reference": "42c131a31b93c440ad49061b599fa218f06f93be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/gif/zipball/42c131a31b93c440ad49061b599fa218f06f93be", + "reference": "42c131a31b93c440ad49061b599fa218f06f93be", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "phpstan/phpstan": "^1", + "phpunit/phpunit": "^10.0", + "slevomat/coding-standard": "~8.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Gif\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "Native PHP GIF Encoder/Decoder", + "homepage": "https://github.com/intervention/gif", + "keywords": [ + "animation", + "gd", + "gif", + "image" + ], + "support": { + "issues": "https://github.com/Intervention/gif/issues", + "source": "https://github.com/Intervention/gif/tree/4.2.0" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + }, + { + "url": "https://ko-fi.com/interventionphp", + "type": "ko_fi" + } + ], + "time": "2024-09-20T13:35:02+00:00" + }, + { + "name": "intervention/image", + "version": "3.10.0", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "1ddc9a096b3a641958515700e09be910bf03a5bd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/1ddc9a096b3a641958515700e09be910bf03a5bd", + "reference": "1ddc9a096b3a641958515700e09be910bf03a5bd", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "intervention/gif": "^4.2", + "php": "^8.1" + }, + "require-dev": { + "mockery/mockery": "^1.6", + "phpstan/phpstan": "^2", + "phpunit/phpunit": "^10.0 || ^11.0", + "slevomat/coding-standard": "~8.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "suggest": { + "ext-exif": "Recommended to be able to read EXIF data properly." + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "PHP image manipulation", + "homepage": "https://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "resize", + "thumbnail", + "watermark" + ], + "support": { + "issues": "https://github.com/Intervention/image/issues", + "source": "https://github.com/Intervention/image/tree/3.10.0" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + }, + { + "url": "https://ko-fi.com/interventionphp", + "type": "ko_fi" + } + ], + "time": "2024-12-21T07:41:40+00:00" + }, { "name": "laravel/framework", "version": "v11.36.1", diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index fadebb2..cb25c75 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -15,11 +15,11 @@
All fields are optional and can be left empty
+ « View Profile + +- OurSpace URL: + Federation handle:
-{{ route ('users.show', [ 'user' => $user ]) }}
+@php echo "@" . $user->name . "@" . explode ("/", env ("APP_URL"))[2] @endphp