Skip to content

Commit

Permalink
Merge pull request #135 from thedevdojo/socialiteControllerUserModel
Browse files Browse the repository at this point in the history
Adding updates to allow the socialite user to use a custom model
  • Loading branch information
tnylea authored Oct 25, 2024
2 parents ae99803 + ad8d9c8 commit 2a78e2e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 77 deletions.
87 changes: 19 additions & 68 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Authenticaiton Tests
name: Authentication Tests

on:
push:
branches: [main]
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
Expand All @@ -30,17 +30,13 @@ jobs:
- name: Setup Laravel Application
run: composer create-project --prefer-dist laravel/laravel laravel_app --no-interaction

- name: Set Working Directory
run: echo "Change directory context to Laravel app"
working-directory: ./laravel_app

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
id: extract_branch

- name: Install DevDojo Auth from current branch
run: composer require devdojo/auth:dev-${{ env.branch }} --with-all-dependencies
run: "composer require devdojo/auth:dev-${{ env.branch }} --with-all-dependencies"
working-directory: ./laravel_app

- name: Publish the DevDojo Auth Assets
Expand All @@ -65,41 +61,31 @@ jobs:
run: touch database/database.sqlite
working-directory: ./laravel_app

- name: List out .env
run: cat .env
working-directory: ./laravel_app

# Testing on a mac, this command should be:
# sed -i '' 's/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/' .env
# sed -i '' 's/^DB_DATABASE=laravel/#DB_DATABASE=laravel/' .env
- name: Updating values in the .env
run: |
sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/' .env
sed -i 's/^DB_DATABASE=laravel/#DB_DATABASE=laravel/' .env
working-directory: ./laravel_app

- name: Include Doctrine DBAL Package which is used for renaming columns
- name: Include Doctrine DBAL Package
run: composer require doctrine/dbal
working-directory: ./laravel_app

- name: Run the migrations
run: php artisan migrate
working-directory: ./laravel_app

- name: Show contents of composer.json before removing PHPUnit
run: cat composer.json
working-directory: ./laravel_app

# Testing on a mac, this command should be:
# sed -i '' '/"phpunit\/phpunit"/d' composer.json
- name: Remove PHPUnit from composer.json
- name: Clean up composer.json - Remove PHPUnit & trailing commas
run: |
sed -i '/"phpunit\/phpunit"/d' composer.json
sed -i '/"nunomaduro\/collision": "\^8.0",/s/,$//' composer.json
sed -i '/"nunomaduro\/collision": "\^8.1",/s/,$//' composer.json
# Remove any trailing commas before a closing bracket in require-dev
sed -i 's/,\s*}/}/' composer.json
working-directory: ./laravel_app

- name: Show contents of composer.json after removing PHPUnit
run: cat composer.json
- name: Validate composer.json format
run: |
php -r 'if (!json_decode(file_get_contents("composer.json"))) { echo "JSON error: " . json_last_error_msg(); exit(1); }'
working-directory: ./laravel_app

- name: Remove composer.lock and re-run composer install
Expand All @@ -117,25 +103,11 @@ jobs:
composer require protonemedia/laravel-dusk-fakes:^1.6 --dev --with-all-dependencies
working-directory: ./laravel_app

- name: Upgrade Chrome Driver
run: php artisan dusk:chrome-driver --detect
working-directory: ./laravel_app

- name: Start Chrome Driver
run: ./vendor/laravel/dusk/bin/chromedriver-linux &
working-directory: ./laravel_app

- name: Check Chrome & ChromeDriver Versions
- name: Start Chrome Driver and PHP Server
run: |
google-chrome --version
chromedriver --version
- name: Clear all view caches
run: php artisan view:clear
working-directory: ./laravel_app

- name: Run Artisan Serve
run: php artisan serve --no-reload &
php artisan dusk:chrome-driver --detect &
./vendor/laravel/dusk/bin/chromedriver-linux &
php artisan serve --no-reload &
working-directory: ./laravel_app

- name: Run Tests
Expand All @@ -147,25 +119,4 @@ jobs:
APP_URL: http://127.0.0.1:8000
APP_ENV: testing
run: php artisan dusk -vvv
working-directory: ./laravel_app

- name: Upload Screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: screenshots
path: tests/Browser/screenshots
- name: Upload Console Logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: console
path: tests/Browser/console

- name: Move the PHP config file to the root directory
run: cp vendor/devdojo/auth/phpstan.neon phpstan.neon
working-directory: ./laravel_app

- name: Run PHPStan for DevDojo Auth
run: ./vendor/bin/phpstan analyse --memory-limit=1G vendor/devdojo/auth/src
working-directory: ./laravel_app
working-directory: ./laravel_app
4 changes: 2 additions & 2 deletions resources/views/pages/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function authenticate()
@endif

@if($showSocialProviderInfo)
<div class="p-4 text-sm rounded-md border bg-zinc-50 border-zinc-200">
<div class="p-4 text-sm border rounded-md bg-zinc-50 border-zinc-200">
<span>{{ str_replace('__social_providers_list__', implode(', ', $userSocialProviders), config('devdojo.auth.language.login.social_auth_authenticated_message')) }}</span>
<button wire:click="editIdentity" type="button" class="underline translate-x-0.5">{{ config('devdojo.auth.language.login.change_email') }}</button>
</div>
Expand All @@ -169,7 +169,7 @@ public function authenticate()
@if($showPasswordField)
<x-auth::elements.input :label="config('devdojo.auth.language.login.password')" type="password" wire:model="password" id="password" data-auth="password-input" />
<x-auth::elements.checkbox :label="config('devdojo.auth.language.login.remember_me')" wire:model="rememberMe" id="remember-me" data-auth="remember-me-input" />
<div class="flex justify-between items-center mt-6 text-sm leading-5">
<div class="flex items-center justify-between mt-6 text-sm leading-5">
<x-auth::elements.text-link href="{{ route('auth.password.request') }}" data-auth="forgot-password-link">{{ config('devdojo.auth.language.login.forget_password') }}</x-auth::elements.text-link>
</div>
@endif
Expand Down
8 changes: 4 additions & 4 deletions resources/views/pages/auth/setup/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<x-auth::layouts.setup>

@volt('auth.setup')
<section class="px-4 py-14 mx-auto max-w-screen-lg">
<section class="max-w-screen-lg px-4 mx-auto py-14">
@if(!file_exists(base_path('config/devdojo/auth/settings.php')))
<x-auth::setup.config-notification />
@endif
Expand All @@ -31,16 +31,16 @@
<x-auth::setup.welcome-card link="auth/setup/language" icon="language" title="Update Language Copy" description="Update the text copy on your login, registration, and other authentication pages"></x-auth::setup.welcome-card>
<x-auth::setup.welcome-card link="auth/setup/settings" icon="settings" title="Modify Settings" description="Adjust specific authentication features and enable/disable functionality."></x-auth::setup.welcome-card>
</div>
<div @click="preview=true" class="flex items-center px-7 py-5 mt-6 space-x-5 w-full h-auto bg-white rounded-md border duration-300 ease-out cursor-pointer hover:bg-zinc-50 border-zinc-200">
<span class="block flex-shrink-0 w-24 h-24">
<div @click="preview=true" class="flex items-center w-full h-auto py-5 mt-6 space-x-5 duration-300 ease-out bg-white border rounded-md cursor-pointer px-7 hover:bg-zinc-50 border-zinc-200">
<span class="flex-shrink-0 block w-24 h-24">
@include('auth::includes.setup.icons.preview')
</span>
<div class="relative">
<p class="text-lg font-semibold text-zinc-800">Preview Your Authentication Pages</p>
<p class="text-sm underline">Click here to see what your authentication pages look like.</p>
</div>
</div>
<div class="relative px-5 py-4 mt-6 w-full text-gray-900 bg-gray-100 rounded-md border border-gray-200 dark:bg-zinc-700 dark:text-gray-300 dark:border-gray-700">
<div class="relative w-full px-5 py-4 mt-6 text-gray-900 bg-gray-100 border border-gray-200 rounded-md dark:bg-zinc-700 dark:text-gray-300 dark:border-gray-700">
<div class="text-sm opacity-80">To learn more about this authentication package, be sure to <a href="https://auth.devdojo.com/docs" target="_blank" class="underline">visit the documentation</a> or <a href="https://github.com/thedevdojo/auth" target="_blank" class="underline">view the project on Github</a>.</div>
</div>
</section>
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Controllers/SocialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Devdojo\Auth\Models\SocialProvider;
use Devdojo\Auth\Models\SocialProviderUser;
use Devdojo\Auth\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
Expand Down Expand Up @@ -76,7 +75,7 @@ private function findOrCreateProviderUser($socialiteUser, $driver)
return $providerUser;
}

$user = User::where('email', $socialiteUser->getEmail())->first();
$user = app(config('auth.providers.users.model'))->where('email', $socialiteUser->getEmail())->first();

if ($user) {
$existingProvider = $user->socialProviders()->first();
Expand All @@ -95,7 +94,7 @@ private function findOrCreateProviderUser($socialiteUser, $driver)

private function createUser($socialiteUser)
{
return User::create([
return app(config('auth.providers.users.model'))->create([
'name' => $socialiteUser->getName(),
'email' => $socialiteUser->getEmail(),
'email_verified_at' => now(),
Expand Down

0 comments on commit 2a78e2e

Please sign in to comment.