diff --git a/.env.example b/.env.example index dee21d6..b011629 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,9 @@ APP_KEY= APP_DEBUG=true APP_URL=http://localhost +GOOGLE_CLIENT_ID= +GOOGLE_CLIENT_SECRET= + LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php new file mode 100644 index 0000000..3d23f8e --- /dev/null +++ b/app/Http/Controllers/AuthController.php @@ -0,0 +1,36 @@ +redirect(); + } + + public function callback() + { + try { + $googleUser = Socialite::driver('google')->user(); + } catch(InvalidStateException) { + return redirect()->route('login'); + } + + $user = User::updateOrCreate([ + 'email' => $googleUser->email + ], [ + 'name' => $googleUser->name, + 'avatar' => $googleUser->avatar + ]); + + auth()->login($user); + + return redirect()->route('dashboard'); + } +} diff --git a/app/Livewire/Dashboard/Dashboard.php b/app/Livewire/Dashboard/Dashboard.php index 1f2fee4..031ac48 100644 --- a/app/Livewire/Dashboard/Dashboard.php +++ b/app/Livewire/Dashboard/Dashboard.php @@ -2,7 +2,7 @@ namespace App\Livewire\Dashboard; -use Illuminate\Http\Request; +use App\Models\Envelope; use Livewire\Attributes\Locked; use Livewire\Attributes\Title; use Livewire\Component; @@ -10,29 +10,24 @@ class Dashboard extends Component { #[Locked] - public array $envelopes = []; + public $envelopes = []; public function mount() { $this->envelopes = auth()->user()->envelopes; } - public function deleteEnvelope(Envelope $envelope) + public function delete(Envelope $envelope) { $this->authorize('delete', $envelope); $envelope->delete(); } - public function archiveEnvelope(Envelope $envelope, bool $newValue) + public function archive(Envelope $envelope) { $this->authorize('update', $envelope); - $envelope->update(['archived' => $newValue]); - } - - public function renameEnvelope(Envelope $envelope, string $newName) - { - $this->authorize('update', $envelope); - $envelope->update(['name' => $newName]); + $envelope->archived = !$envelope->archived; + $envelope->update(); } #[Title('Dashboard — Payback')] diff --git a/app/Livewire/Dashboard/Envelope.php b/app/Livewire/Dashboard/Envelope.php deleted file mode 100644 index e6e91d9..0000000 --- a/app/Livewire/Dashboard/Envelope.php +++ /dev/null @@ -1,13 +0,0 @@ -authorize('update', $this->envelope); + $this->envelope->update(['name' => $name]); + } + + public function render() + { + return view('livewire.dashboard.envelope-card'); + } +} diff --git a/composer.json b/composer.json index 7b39f06..0cff917 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.10", "laravel/sanctum": "^3.3", + "laravel/socialite": "^5.10", "laravel/tinker": "^2.8", "livewire/livewire": "^3.2" }, diff --git a/composer.lock b/composer.lock index 295d735..83954bc 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": "aab9b98b3a49f8ec9341a8e579bda099", + "content-hash": "a2949c4fb3bc36a0efb8fa64b57f48e1", "packages": [ { "name": "brick/math", @@ -1407,6 +1407,76 @@ }, "time": "2023-11-08T14:08:06+00:00" }, + { + "name": "laravel/socialite", + "version": "v5.10.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/socialite.git", + "reference": "f376b6eda9084899e37ac08bafd64a95edf9c6c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/socialite/zipball/f376b6eda9084899e37ac08bafd64a95edf9c6c0", + "reference": "f376b6eda9084899e37ac08bafd64a95edf9c6c0", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "illuminate/contracts": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/http": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0", + "league/oauth1-client": "^1.10.1", + "php": "^7.2|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.0|^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Socialite\\SocialiteServiceProvider" + ], + "aliases": { + "Socialite": "Laravel\\Socialite\\Facades\\Socialite" + } + } + }, + "autoload": { + "psr-4": { + "Laravel\\Socialite\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.", + "homepage": "https://laravel.com", + "keywords": [ + "laravel", + "oauth" + ], + "support": { + "issues": "https://github.com/laravel/socialite/issues", + "source": "https://github.com/laravel/socialite" + }, + "time": "2023-10-30T22:09:58+00:00" + }, { "name": "laravel/tinker", "version": "v2.8.2", @@ -1870,6 +1940,82 @@ ], "time": "2023-10-17T14:13:20+00:00" }, + { + "name": "league/oauth1-client", + "version": "v1.10.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/oauth1-client.git", + "reference": "d6365b901b5c287dd41f143033315e2f777e1167" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/d6365b901b5c287dd41f143033315e2f777e1167", + "reference": "d6365b901b5c287dd41f143033315e2f777e1167", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-openssl": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "guzzlehttp/psr7": "^1.7|^2.0", + "php": ">=7.1||>=8.0" + }, + "require-dev": { + "ext-simplexml": "*", + "friendsofphp/php-cs-fixer": "^2.17", + "mockery/mockery": "^1.3.3", + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5||9.5" + }, + "suggest": { + "ext-simplexml": "For decoding XML-based responses." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev", + "dev-develop": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\OAuth1\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Corlett", + "email": "bencorlett@me.com", + "homepage": "http://www.webcomm.com.au", + "role": "Developer" + } + ], + "description": "OAuth 1.0 Client Library", + "keywords": [ + "Authentication", + "SSO", + "authorization", + "bitbucket", + "identity", + "idp", + "oauth", + "oauth1", + "single sign on", + "trello", + "tumblr", + "twitter" + ], + "support": { + "issues": "https://github.com/thephpleague/oauth1-client/issues", + "source": "https://github.com/thephpleague/oauth1-client/tree/v1.10.1" + }, + "time": "2022-04-15T14:02:14+00:00" + }, { "name": "livewire/livewire", "version": "v3.2.1", diff --git a/config/services.php b/config/services.php index 0ace530..725dbf6 100644 --- a/config/services.php +++ b/config/services.php @@ -31,4 +31,10 @@ 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), ], + 'google' => [ + 'client_id' => env('GOOGLE_CLIENT_ID'), + 'client_secret' => env('GOOGLE_CLIENT_SECRET'), + 'redirect' => '/auth/callback', + ], + ]; diff --git a/database/factories/ReceiptFactory.php b/database/factories/ReceiptFactory.php index 768ac40..ffca870 100644 --- a/database/factories/ReceiptFactory.php +++ b/database/factories/ReceiptFactory.php @@ -19,6 +19,7 @@ public function definition(): array { return [ 'name' => fake()->sentence(4), + 'store' => fake()->company(), 'amount' => fake()->numberBetween(1_00, 50_00), 'description' => fake()->paragraph(), 'category_id' => Category::inRandomOrder()->first(), diff --git a/database/migrations/2023_11_28_043736_create_receipts_table.php b/database/migrations/2023_11_28_043741_create_receipts_table.php similarity index 96% rename from database/migrations/2023_11_28_043736_create_receipts_table.php rename to database/migrations/2023_11_28_043741_create_receipts_table.php index 4e24a34..71c0afb 100644 --- a/database/migrations/2023_11_28_043736_create_receipts_table.php +++ b/database/migrations/2023_11_28_043741_create_receipts_table.php @@ -17,6 +17,7 @@ public function up(): void $table->id(); $table->string('name'); + $table->string('store'); $table->integer('amount'); $table->text('description')->default(''); $table->string('image')->nullable(); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0a9ae59..a377211 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -8,6 +8,7 @@ use App\Models\Receipt; use App\Models\User; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\App; class DatabaseSeeder extends Seeder { @@ -16,10 +17,12 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - User::factory(10)->has( - Envelope::factory(5)->has( - Receipt::factory(10) - ) - )->create(); + if(App::environment() !== 'production') { + User::factory(10)->has( + Envelope::factory(5)->has( + Receipt::factory(10) + ) + )->create(); + } } } diff --git a/resources/views/livewire/dashboard/dashboard.blade.php b/resources/views/livewire/dashboard/dashboard.blade.php index be88eee..4b423b3 100644 --- a/resources/views/livewire/dashboard/dashboard.blade.php +++ b/resources/views/livewire/dashboard/dashboard.blade.php @@ -1,5 +1,7 @@ -
- @foreach($envelopes as $envelope) - @livewire('dashboard.envelope', $envelope) - @endforeach +
+
+ @foreach($envelopes as $envelope) + + @endforeach +
diff --git a/resources/views/livewire/dashboard/envelope-card.blade.php b/resources/views/livewire/dashboard/envelope-card.blade.php new file mode 100644 index 0000000..6ea1c9d --- /dev/null +++ b/resources/views/livewire/dashboard/envelope-card.blade.php @@ -0,0 +1,38 @@ +@props(['envelope']) + +@php + $count = $envelope->receipts()->count(); + $count = $count . ' ' . Str::plural('receipt', $count); +@endphp + +
+
+ +
+ +
+
+

{{ $envelope->name }}

+

{{ $count }}

+
+
+
+ +{{--
+ + + + + + +
+
+ --}} \ No newline at end of file diff --git a/resources/views/livewire/dashboard/envelope.blade.php b/resources/views/livewire/dashboard/envelope.blade.php deleted file mode 100644 index db86de0..0000000 --- a/resources/views/livewire/dashboard/envelope.blade.php +++ /dev/null @@ -1,3 +0,0 @@ -
- {{-- Close your eyes. Count to one. That is how long forever feels. --}} -
diff --git a/routes/web.php b/routes/web.php index c64c479..e5bcaaf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,10 +1,14 @@ name('login'); +Route::get('/auth/callback', [AuthController::class, 'callback']); + Route::middleware('auth')->group(function() { - Route::get('/dashboard', Dashboard::class); + Route::get('/dashboard', Dashboard::class)->name('dashboard'); }); \ No newline at end of file diff --git a/tailwind.config.js b/tailwind.config.js index d07d3de..2ca07cc 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -5,7 +5,9 @@ export default { ], theme: { extend: { - + aspectRatio: { + photo: '3/2' + } } }, plugins: []