Skip to content

Commit

Permalink
feat: support Laravel 8. (#48)
Browse files Browse the repository at this point in the history
* feat: support Laravel 8. #44

* ci: failed because bad version #44
  • Loading branch information
sinkcup authored Sep 12, 2020
1 parent 345b1a3 commit e5476c3
Show file tree
Hide file tree
Showing 36 changed files with 209 additions and 193 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/laravel-7.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Laravel 6
name: Laravel 8
on:
push:
branches:
Expand All @@ -22,8 +22,8 @@ jobs:
pecl install xdebug
docker-php-ext-enable xdebug
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
composer require orchestra/testbench:^v4 --dev
./vendor/bin/phpunit --coverage-clover coverage.xml tests/
composer require orchestra/testbench:^v6 --dev
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-filter src/ tests/
- name: codecov
uses: codecov/codecov-action@v1
with:
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Laravel UI Socialite

[![Laravel 6](https://github.com/laravel-fans/laravel-ui-socialite/workflows/Laravel%206/badge.svg)](https://github.com/laravel-fans/laravel-ui-socialite/actions)
[![Laravel 7](https://github.com/laravel-fans/laravel-ui-socialite/workflows/Laravel%207/badge.svg)](https://github.com/laravel-fans/laravel-ui-socialite/actions)
[![Laravel 8](https://github.com/laravel-fans/laravel-ui-socialite/workflows/Laravel%208/badge.svg)](https://github.com/laravel-fans/laravel-ui-socialite/actions)
[![codecov](https://codecov.io/gh/laravel-fans/laravel-ui-socialite/branch/main/graph/badge.svg)](https://codecov.io/gh/laravel-fans/laravel-ui-socialite)
[![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)](https://github.com/laravel-fans/laravel-ui-socialite/blob/main/LICENSE)

Expand All @@ -13,15 +12,14 @@ When logged in, you can link all providers to the current user, and login with t

Special handling for [WeChat](https://sinkcup.github.io/laravel-socialite-wechat-login).

supporting Laravel 6, 7...

## install

```
composer require laravel-fans/ui-socialite
php artisan ui vue
php artisan ui:auth
php artisan ui:socialite
php artisan vendor:publish --provider="LaravelFans\UiSocialite\UiSocialiteServiceProvider"
php artisan migrate
```

Expand All @@ -44,7 +42,7 @@ add to `.env`:
AUTH_SOCIAL_LOGIN_PROVIDERS=Facebook,Twitter,Linkedin,Google,GitHub,GitLab,Bitbucket,wechat_web,wechat_service_account
GITHUB_CLIENT_ID=foo
GITHUB_CLIENT_SECRET=bar
GITHUB_CALLBACK_URL=http://localhost/login/github/callback
GITHUB_CALLBACK_URL=http://127.0.0.1:8000/login/github/callback
GITHUB_SCOPES=user:email,public_repo
# disable password login
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"description": "Automatically generate database, pages, and routes for Laravel Socialite",
"type": "library",
"require": {
"php": ">=7.2",
"laravel/framework": "^v6.18.37 | ^v7.28.1",
"php": ">=7.3",
"laravel/framework": "^v8.1.0",
"laravel/socialite": ">=v4.4.1",
"doctrine/dbal": ">=2.9",
"phlak/semver": ">=2.0",
"laravel/ui": ">=v1.2.0"
"laravel/ui": ">=v3.0.0"
},
"suggest": {
"laravel-fans/socialite-providers": "Providers for Laravel Socialite"
Expand All @@ -28,6 +28,7 @@
"autoload-dev": {
"psr-4": {
"App\\": "vendor/orchestra/testbench-core/laravel/app/",
"Database\\Factories\\": "vendor/orchestra/testbench-core/laravel/database/factories/",
"LaravelFans\\UiSocialite\\Tests\\": "tests/"
}
},
Expand All @@ -40,9 +41,9 @@
}
},
"require-dev": {
"orchestra/testbench": "^v4.8.0 | ^v5.5.0",
"orchestra/testbench": "^v6.0.0",
"squizlabs/php_codesniffer": ">=3.5.6",
"fzaninotto/faker": ">=v1.9.1",
"phpunit/phpunit": "^8.5.8"
"phpunit/phpunit": "^9.3.8"
}
}
File renamed without changes.
36 changes: 36 additions & 0 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
66 changes: 29 additions & 37 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>

<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="clover.xml"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<logging/>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace LaravelFans\UiSocialite\Socialite\Controllers;
namespace LaravelFans\UiSocialite\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

namespace LaravelFans\UiSocialite\Socialite\Controllers\Settings;
namespace LaravelFans\UiSocialite\Controllers\Settings;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ViewErrorBag;
use Illuminate\Validation\Rule;
use LaravelFans\UiSocialite\SocialAccount;
use LaravelFans\UiSocialite\Socialite\Controllers\Controller;
use LaravelFans\UiSocialite\Socialite\Controllers\SocialiteLoginController;
use LaravelFans\UiSocialite\Models\SocialAccount;
use LaravelFans\UiSocialite\Controllers\Controller;

class ProfileController extends Controller
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace LaravelFans\UiSocialite\Socialite\Controllers;
namespace LaravelFans\UiSocialite\Controllers;

use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\ViewErrorBag;
Expand Down Expand Up @@ -62,6 +62,7 @@ public function redirectToProvider(string $providerSlug)
* Obtain the user information from Socialite Provider.
*
* @param string $providerSlug
* @param SocialiteService $socialiteService
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handleProviderCallback(string $providerSlug, SocialiteService $socialiteService)
Expand Down
5 changes: 4 additions & 1 deletion src/SocialAccount.php → src/Models/SocialAccount.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

namespace LaravelFans\UiSocialite;
namespace LaravelFans\UiSocialite\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Socialite\AbstractUser;

class SocialAccount extends Model
{
use HasFactory;

protected $guarded = [];
protected $casts = [
'raw' => 'array',
Expand Down
32 changes: 0 additions & 32 deletions src/Socialite/stubs/database/factories/SocialAccountFactory.stub

This file was deleted.

8 changes: 0 additions & 8 deletions src/Socialite/stubs/routes.stub

This file was deleted.

12 changes: 4 additions & 8 deletions src/SocialiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function exportViews()
}

$version = new Version(app()->version());
$path = __DIR__ . '/Socialite/' . $this->argument('type') . '-stubs/';
$path = __DIR__ . '/' . $this->argument('type') . '-stubs/';
$file_for_version = $key . '_' . $version->major . '.' . $version->minor;
$file_path = file_exists($path . $file_for_version) ? $path . $file_for_version : $path . $key;
copy($file_path, $view);
Expand All @@ -119,16 +119,12 @@ protected function exportBackend()
$this->compileControllerStub('settings/ProfileController.stub')
);
copy(
__DIR__ . '/Socialite/stubs/database/factories/SocialAccountFactory.stub',
database_path('factories/SocialAccountFactory.php')
);
copy(
__DIR__ . '/Socialite/stubs/tests/TestCase.stub',
__DIR__ . '/stubs/tests/TestCase.stub',
app_path() . '/../tests/TestCase.php'
);

$web_routes = file_get_contents(base_path('routes/web.php'));
foreach (explode("\n", file_get_contents(__DIR__ . '/Socialite/stubs/routes.stub')) as $line) {
foreach (explode("\n", file_get_contents(__DIR__ . '/stubs/routes.stub')) as $line) {
if (empty($line)) {
continue;
}
Expand Down Expand Up @@ -167,7 +163,7 @@ protected function compileStub(string $path)
return str_replace(
'{{namespace}}',
$this->laravel->getNamespace(),
file_get_contents(__DIR__ . '/Socialite/stubs/' . $path)
file_get_contents(__DIR__ . '/stubs/' . $path)
);
}

Expand Down
1 change: 1 addition & 0 deletions src/SocialiteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Log;
use Laravel\Socialite\Facades\Socialite;
use LaravelFans\UiSocialite\Models\SocialAccount;

class SocialiteService
{
Expand Down
11 changes: 5 additions & 6 deletions src/UiSocialiteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public function boot()
SocialiteCommand::class,
]);
}
// HACK: package migrations be migrated before laravel migrations when run test
// error: There is no column with name 'password' on table 'users'.
if ($this->app->config['app']['name'] != 'testbench') {
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
}

$this->publishes([
__DIR__ . '/../database/migrations' => database_path('migrations'),
], 'ui-socialite-migrations');
}

/**
Expand All @@ -32,7 +31,7 @@ public function boot()
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/config/auth.php', 'auth');
$this->mergeConfigFrom(__DIR__ . '/../config/auth.php', 'auth');
$this->app->singleton(SocialiteService::class, function ($app) {
return new SocialiteService($app);
});
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e5476c3

Please sign in to comment.