From 6c042349bab978c8efd8279309a8affb546ba9cf Mon Sep 17 00:00:00 2001 From: Lewis Larsen Date: Sat, 15 Jun 2024 20:15:07 +0100 Subject: [PATCH] feat: added github login ability badge to user settings --- app/Models/User.php | 5 + .../update-profile-information-form.blade.php | 108 ++++++++++-------- tests/Unit/UserTest.php | 14 +++ 3 files changed, 80 insertions(+), 47 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 65c76001..c6e436de 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -82,6 +82,11 @@ public function backupTasklogCountToday(): int })->whereDate('created_at', today()->timezone($this->timezone ?? 'UTC'))->count(); } + public function canLoginWithGithub(): bool + { + return $this->github_id !== null; + } + protected function firstName(): Attribute { return new Attribute(function ($value) { diff --git a/resources/views/livewire/profile/update-profile-information-form.blade.php b/resources/views/livewire/profile/update-profile-information-form.blade.php index f453bff5..53fac411 100644 --- a/resources/views/livewire/profile/update-profile-information-form.blade.php +++ b/resources/views/livewire/profile/update-profile-information-form.blade.php @@ -68,6 +68,20 @@ public function sendVerification(): void
+ @if (Auth::user()->canLoginWithGithub()) +
+
+ + + {{ __('You can sign in to :app with GitHub.', ['app' => config('app.name')]) }} + +
+
+ @svg('heroicon-o-check', 'w-6 h-6 text-green-600 dark:text-green-400 inline mr-2') +
+
+ @endif
@@ -80,56 +94,56 @@ class="ml-4 text-sm text-gray-600 dark:text-gray-400 underline hover:text-gray-9
-
- - - -
+
+ + + +
-
- - - - - @if (auth()->user() instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! auth()->user()->hasVerifiedEmail()) -
-

- {{ __('Your email address is unverified.') }} - - +

+ + + + + @if (auth()->user() instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! auth()->user()->hasVerifiedEmail()) +
+

+ {{ __('Your email address is unverified.') }} + + +

+ + @if (session('status') === 'verification-link-sent') +

+ {{ __('A new verification link has been sent to your email address.') }}

+ @endif +
+ @endif +
- @if (session('status') === 'verification-link-sent') -

- {{ __('A new verification link has been sent to your email address.') }} -

- @endif -
- @endif -
- -
- - - @foreach (formatTimezones() as $identifier => $timezone) - - @endforeach - - - {{ __('Your timezone is used to display dates and times to you in your local time.') }} - - -
+
+ + + @foreach (formatTimezones() as $identifier => $timezone) + + @endforeach + + + {{ __('Your timezone is used to display dates and times to you in your local time.') }} + + +
-
- - {{ __('Save') }} - -
+
+ + {{ __('Save') }} + +
diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index be17f0fe..9decb4fa 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -79,3 +79,17 @@ $this->assertEquals(0, $user->backupTaskLogCountToday()); }); + +test('returns true if can login with github', function () { + + $user = User::factory()->create(['github_id' => 1]); + + $this->assertTrue($user->canLoginWithGithub()); +}); + +test('returns false if can not login with github', function () { + + $user = User::factory()->create(); + + $this->assertFalse($user->canLoginWithGithub()); +});