diff --git a/README.md b/README.md index f8d4c72..f291027 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ # Laravel Make Auth Socialite -Automatically generate database, pages and routes for Laravel Socialite. Just like `php artisan make:auth`. +Automatically generate database, pages, and routes for Laravel Socialite. Just like `php artisan make:auth`. -supporting Laravel 5.5, 5.6 and 5.7! +Login with multiple providers using the same email will be determined as one user. + +When logged in, you can link all providers to the current user, and login with them next time. + +Special handling for [WeChat](https://sinkcup.github.io/laravel-socialite-wechat-login). + +supporting Laravel 5.5 and 5.8! ## install ``` -php artisan make:auth composer require sinkcup/laravel-make-auth-socialite php artisan make:auth-socialite --force php artisan migrate @@ -15,7 +20,7 @@ php artisan migrate ## config -add providers to `config/services.php`: +add to `config/services.php`: ``` 'github' => [ @@ -25,7 +30,7 @@ add providers to `config/services.php`: ], ``` -ENV: +add to `.env`: ``` AUTH_SOCIAL_LOGIN_PROVIDERS=Facebook,GitHub,Google @@ -36,7 +41,7 @@ GITHUB_CALLBACK_URL=http://laravel-demo.localhost/login/github/callback ## screenshots -![Login page](https://user-images.githubusercontent.com/4971414/50548717-bac5f100-0c8c-11e9-974a-45dfbe1c41da.png) -![GitHub OAuth Login](https://user-images.githubusercontent.com/4971414/50548725-d3cea200-0c8c-11e9-9b01-9b949bcb6b4d.png) -![logged in](https://user-images.githubusercontent.com/4971414/50548746-24de9600-0c8d-11e9-8262-213ffa1309be.png) -![database](https://user-images.githubusercontent.com/4971414/50548808-f2816880-0c8d-11e9-8227-d8128f040c30.png) +![Laravel Socialite Login page](https://user-images.githubusercontent.com/4971414/59020731-2a17c080-887d-11e9-8cc7-c8c46f97dd1b.png) +![GitHub OAuth Login](https://user-images.githubusercontent.com/4971414/59006611-764f0a80-8855-11e9-9ac9-0f4de8ff6e77.png) +![Laravel Socialite Profile page and Linked Accounts](https://user-images.githubusercontent.com/4971414/59092834-120b7400-8945-11e9-8b1d-ae50c862e6a8.png) +![Laravel Socialite link multiple providers to one user](https://user-images.githubusercontent.com/4971414/59086178-876e4900-8933-11e9-8dad-e2a449a5689e.png) diff --git a/composer.json b/composer.json index a4ba5b1..a2e741f 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,12 @@ { "name": "sinkcup/laravel-make-auth-socialite", - "description": "Automatically generate database, pages and routes for Laravel Socialite", + "description": "Automatically generate database, pages, and routes for Laravel Socialite", "type": "library", "require": { - "laravel/framework": "^5.7", - "laravel/socialite": "^4.0", - "doctrine/dbal": "^2.9" + "laravel/framework": "~5.5.0|~5.8.0|~5.9.0", + "laravel/socialite": "~3.3.0|~4.1.0", + "doctrine/dbal": "^2.9", + "phlak/semver": "^2.0" }, "license": "MIT", "authors": [ diff --git a/src/Commands/MakeAuthSocialite.php b/src/Commands/MakeAuthSocialite.php index a476b59..acfd69b 100644 --- a/src/Commands/MakeAuthSocialite.php +++ b/src/Commands/MakeAuthSocialite.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Illuminate\Console\DetectsApplicationNamespace; +use PHLAK\SemVer\Version; class MakeAuthSocialite extends Command { @@ -102,11 +103,11 @@ protected function exportViews() continue; } } - - copy( - __DIR__.'/stubs/make/views/'.$key, - $view - ); + $version = new Version(app()->version()); + $path = __DIR__.'/stubs/make/views/'; + $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); } } diff --git a/src/Commands/stubs/make/views/auth/login.stub_5.5 b/src/Commands/stubs/make/views/auth/login.stub_5.5 new file mode 100644 index 0000000..6440f8c --- /dev/null +++ b/src/Commands/stubs/make/views/auth/login.stub_5.5 @@ -0,0 +1,103 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Social Login
+ +
+ @if (in_array('wechat_web', $social_login_providers)) + +
+ + @php + unset($social_login_providers[array_search('wechat_web', $social_login_providers)]); + @endphp + @endif + + +
+
+ +
+
Login
+ +
+
+ {{ csrf_field() }} + +
+ + +
+ + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif +
+
+ +
+
+
+ +
+
+
+ +
+
+ + + + Forgot Your Password? + +
+
+
+
+
+
+
+
+@endsection diff --git a/src/Commands/stubs/make/views/user/profile_edit.stub_5.5 b/src/Commands/stubs/make/views/user/profile_edit.stub_5.5 new file mode 100644 index 0000000..d157c9c --- /dev/null +++ b/src/Commands/stubs/make/views/user/profile_edit.stub_5.5 @@ -0,0 +1,81 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
{{ __('Social Login') }}
+ +
+
+ {{ csrf_field() }} + {{ method_field('PUT') }} + +
+ @if ($user->avatar) + +
+ {{ $user->name }} avatar +
+ @endif + + + +
+ + + @if ($errors->has('name')) + + {{ $errors->first('name') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+ +
+
+ +
+
+
+
+
+ +
+
{{ __('Linked Accounts') }}
+ +
+
    + @foreach ($social_login_providers as $provider) +
  • + @if (in_array(strtolower($provider), $linked_providers)) + {{ __($provider) }} + @else + {{ __($provider) }} + @endif +
  • + @endforeach +
+
+
+
+
+
+@endsection