From 076693efc9705937464f29b134397abd1040d821 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 4 Feb 2017 11:01:49 +0000 Subject: [PATCH] Added facebook, slack & twitter sign in options. Also added icon svg blade helper. Closes #125. Starts #213. Requires documentation. --- app/Providers/AppServiceProvider.php | 4 ++ app/Providers/EventServiceProvider.php | 5 +- app/Providers/SocialiteServiceProvider.php | 36 ---------- app/Services/SocialAuthService.php | 3 +- app/helpers.php | 12 +++- composer.json | 3 +- composer.lock | 83 +++++++++++++++++++++- config/app.php | 2 +- config/services.php | 18 +++++ resources/assets/icons/facebook.svg | 1 + resources/assets/icons/github.svg | 1 + resources/assets/icons/google.svg | 1 + resources/assets/icons/slack.svg | 1 + resources/assets/icons/twitter.svg | 1 + resources/assets/sass/_text.scss | 10 ++- resources/views/auth/login.blade.php | 10 ++- resources/views/auth/register.blade.php | 10 ++- resources/views/public.blade.php | 4 +- resources/views/users/edit.blade.php | 24 ++----- 19 files changed, 150 insertions(+), 79 deletions(-) delete mode 100644 app/Providers/SocialiteServiceProvider.php create mode 100644 resources/assets/icons/facebook.svg create mode 100644 resources/assets/icons/github.svg create mode 100644 resources/assets/icons/google.svg create mode 100644 resources/assets/icons/slack.svg create mode 100644 resources/assets/icons/twitter.svg diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 40a1eef3d..118271f51 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -17,6 +17,10 @@ class AppServiceProvider extends ServiceProvider $imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/tiff', 'image/webp']; return in_array($value->getMimeType(), $imageMimes); }); + + \Blade::directive('icon', function($expression) { + return ""; + }); } /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3802f20c0..d82a560f9 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -4,6 +4,7 @@ namespace BookStack\Providers; use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; +use SocialiteProviders\Manager\SocialiteWasCalled; class EventServiceProvider extends ServiceProvider { @@ -13,8 +14,8 @@ class EventServiceProvider extends ServiceProvider * @var array */ protected $listen = [ - 'BookStack\Events\SomeEvent' => [ - 'BookStack\Listeners\EventListener', + SocialiteWasCalled::class => [ + 'SocialiteProviders\Slack\SlackExtendSocialite@handle', ], ]; diff --git a/app/Providers/SocialiteServiceProvider.php b/app/Providers/SocialiteServiceProvider.php deleted file mode 100644 index f7fb30f81..000000000 --- a/app/Providers/SocialiteServiceProvider.php +++ /dev/null @@ -1,36 +0,0 @@ -app->bindShared('Laravel\Socialite\Contracts\Factory', function ($app) { - return new SocialiteManager($app); - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return ['Laravel\Socialite\Contracts\Factory']; - } -} \ No newline at end of file diff --git a/app/Services/SocialAuthService.php b/app/Services/SocialAuthService.php index 5edd4cad7..710f95696 100644 --- a/app/Services/SocialAuthService.php +++ b/app/Services/SocialAuthService.php @@ -14,7 +14,7 @@ class SocialAuthService protected $socialite; protected $socialAccount; - protected $validSocialDrivers = ['google', 'github']; + protected $validSocialDrivers = ['google', 'github', 'facebook', 'slack', 'twitter']; /** * SocialAuthService constructor. @@ -211,7 +211,6 @@ class SocialAuthService */ public function detachSocialAccount($socialDriver) { - session(); user()->socialAccounts()->where('driver', '=', $socialDriver)->delete(); session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => title_case($socialDriver)])); return redirect(user()->getEditUrl()); diff --git a/app/helpers.php b/app/helpers.php index 6decb08e9..8103ad1ff 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -117,6 +117,16 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null) return app('redirect')->to($to, $status, $headers, $secure); } +function icon($name, $attrs = []) { + $iconPath = resource_path('assets/icons/' . $name . '.svg'); + $attrString = ' '; + foreach ($attrs as $attrName => $attr) { + $attrString .= $attrName . '="' . $attr . '" '; + } + $fileContents = file_get_contents($iconPath); + return str_replace(' env('APP_URL') . '/login/service/google/callback', ], + 'slack' => [ + 'client_id' => env('SLACK_APP_ID', false), + 'client_secret' => env('SLACK_APP_SECRET', false), + 'redirect' => env('APP_URL') . '/login/service/slack/callback', + ], + + 'facebook' => [ + 'client_id' => env('FACEBOOK_APP_ID', false), + 'client_secret' => env('FACEBOOK_APP_SECRET', false), + 'redirect' => env('APP_URL') . '/login/service/facebook/callback', + ], + + 'twitter' => [ + 'client_id' => env('TWITTER_APP_ID', false), + 'client_secret' => env('TWITTER_APP_SECRET', false), + 'redirect' => env('APP_URL') . '/login/service/twitter/callback', + ], + 'ldap' => [ 'server' => env('LDAP_SERVER', false), 'dn' => env('LDAP_DN', false), diff --git a/resources/assets/icons/facebook.svg b/resources/assets/icons/facebook.svg new file mode 100644 index 000000000..7bfafd226 --- /dev/null +++ b/resources/assets/icons/facebook.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/icons/github.svg b/resources/assets/icons/github.svg new file mode 100644 index 000000000..ae6dc6f7f --- /dev/null +++ b/resources/assets/icons/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/icons/google.svg b/resources/assets/icons/google.svg new file mode 100644 index 000000000..34ed1603b --- /dev/null +++ b/resources/assets/icons/google.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/icons/slack.svg b/resources/assets/icons/slack.svg new file mode 100644 index 000000000..5280f971f --- /dev/null +++ b/resources/assets/icons/slack.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/icons/twitter.svg b/resources/assets/icons/twitter.svg new file mode 100644 index 000000000..fa4d59efd --- /dev/null +++ b/resources/assets/icons/twitter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/sass/_text.scss b/resources/assets/sass/_text.scss index aac4298ea..79d3c3a92 100644 --- a/resources/assets/sass/_text.scss +++ b/resources/assets/sass/_text.scss @@ -16,7 +16,7 @@ h2 { } h3 { font-size: 2.333em; - line-height: 1.571428572em; + line-height: 1.221428572em; margin-top: 0.78571429em; margin-bottom: 0.43137255em; } @@ -71,6 +71,13 @@ a, .link { padding-right: 0; padding-left: $-s; } + &.icon { + display: inline-block; + } + svg { + position: relative; + display: inline-block; + } } /* @@ -84,7 +91,6 @@ p, ul, ol, pre, table, blockquote { hr { border: 0; height: 1px; - border: 0; background: #EAEAEA; margin-bottom: $-l; &.faded { diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 928565156..6c8b1720c 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -33,12 +33,10 @@ @if(count($socialDrivers) > 0)

{{ trans('auth.social_login') }}

- @if(isset($socialDrivers['google'])) - - @endif - @if(isset($socialDrivers['github'])) - - @endif + @foreach($socialDrivers as $driver => $enabled) + @icon($driver, ['width' => 56]) +   + @endforeach @endif diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 7a119ddba..860508df0 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -37,12 +37,10 @@

{{ trans('auth.social_registration') }}

{{ trans('auth.social_registration_text') }}

- @if(isset($socialDrivers['google'])) - - @endif - @if(isset($socialDrivers['github'])) - - @endif + @foreach($socialDrivers as $driver => $enabled) + @icon($driver, ['width' => 56]) +   + @endforeach @endif diff --git a/resources/views/public.blade.php b/resources/views/public.blade.php index 05cf043fd..ea2069b86 100644 --- a/resources/views/public.blade.php +++ b/resources/views/public.blade.php @@ -30,7 +30,7 @@