From cdafbab7b1f9f5c4f8dfd8eabf398ab0e6f3fde3 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 17 Oct 2018 09:41:20 +0100 Subject: [PATCH] possible fix for basic auth --- .gitignore | 3 ++- app/Providers/AppServiceProvider.php | 37 ++++++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index ed04c57d..97b87e3d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ yarn-error.log .Spotlight-V100 .TemporaryItems .Trashes -.VolumeIcon.icns \ No newline at end of file +.VolumeIcon.icns +storage/app/public/avatars/* diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index f2b0504e..b9fc2904 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -65,7 +65,27 @@ class AppServiceProvider extends ServiceProvider $view->with('alt_bg', $alt_bg ); $view->with('allusers', $allusers ); - $view->with('current_user', $current_user ); + $view->with('current_user', $current_user ); + + if(isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION'])) { + list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = + explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); + } + if(!\Auth::check()) { + if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { + $credentials = ['username' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']]; + + if (\Auth::attempt($credentials)) { + // Authentication passed... + $user = \Auth::user(); + \Session::put('current_user', $user); + //session(['current_user' => $user]); + } + } + } + + + }); @@ -76,21 +96,6 @@ class AppServiceProvider extends ServiceProvider if(env('APP_URL') != 'http://localhost') { \URL::forceRootUrl(env('APP_URL')); } - if(isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION'])) { - list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = - explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); - } - if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { - $credentials = ['username' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']]; - - if (\Auth::attempt($credentials)) { - // Authentication passed... - $user = \Auth::user(); - \Session::put('current_user', $user); - //session(['current_user' => $user]); - } - - } }