diff --git a/app/Http/Middleware/DatabaseLookup.php b/app/Http/Middleware/DatabaseLookup.php index 4aff597ca1..a74bdfe24a 100644 --- a/app/Http/Middleware/DatabaseLookup.php +++ b/app/Http/Middleware/DatabaseLookup.php @@ -37,6 +37,8 @@ class DatabaseLookup } } elseif ($guard == 'postmark') { LookupInvitation::setServerByField('message_id', request()->MessageID); + } elseif ($guard == 'license') { + config(['database.default' => DB_NINJA_1]); } return $next($request); diff --git a/app/Http/routes.php b/app/Http/routes.php index 6783e32a1f..be3ee39fc2 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -62,9 +62,11 @@ Route::group(['middleware' => ['lookup:contact', 'auth:client']], function () { Route::get('api/client.activity', ['as' => 'api.client.activity', 'uses' => 'ClientPortalController@activityDatatable']); }); -Route::get('license', 'NinjaController@show_license_payment'); -Route::post('license', 'NinjaController@do_license_payment'); -Route::get('claim_license', 'NinjaController@claim_license'); +Route::group(['middleware' => 'lookup:license'], function () { + Route::get('license', 'NinjaController@show_license_payment'); + Route::post('license', 'NinjaController@do_license_payment'); + Route::get('claim_license', 'NinjaController@claim_license'); +}); Route::post('signup/validate', 'AccountController@checkEmail'); Route::post('signup/submit', 'AccountController@submitSignup'); @@ -91,6 +93,7 @@ Route::get('/login', ['as' => 'login', 'uses' => 'Auth\AuthController@getLoginWr Route::get('/logout', ['as' => 'logout', 'uses' => 'Auth\AuthController@getLogoutWrapper']); Route::get('/recover_password', ['as' => 'forgot', 'uses' => 'Auth\PasswordController@getEmail']); Route::get('/password/reset/{token}', ['as' => 'forgot', 'uses' => 'Auth\PasswordController@getReset']); + Route::group(['middleware' => ['lookup:user']], function () { Route::get('/user/confirm/{confirmation_code}', 'UserController@confirm'); Route::post('/login', ['as' => 'login', 'uses' => 'Auth\AuthController@postLoginWrapper']); @@ -104,6 +107,7 @@ Route::get('/client/logout', ['as' => 'logout', 'uses' => 'ClientAuth\AuthContro Route::get('/client/sessionexpired', ['as' => 'logout', 'uses' => 'ClientAuth\AuthController@getSessionExpired']); Route::get('/client/recover_password', ['as' => 'forgot', 'uses' => 'ClientAuth\PasswordController@getEmail']); Route::get('/client/password/reset/{token}', ['as' => 'forgot', 'uses' => 'ClientAuth\PasswordController@getReset']); + Route::group(['middleware' => ['lookup:contact']], function () { Route::post('/client/login', ['as' => 'login', 'uses' => 'ClientAuth\AuthController@postLogin']); Route::post('/client/recover_password', ['as' => 'forgot', 'uses' => 'ClientAuth\PasswordController@postEmail']); diff --git a/app/Services/AuthService.php b/app/Services/AuthService.php index f9cc9d1ab0..2c395f01ea 100644 --- a/app/Services/AuthService.php +++ b/app/Services/AuthService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\Events\UserLoggedIn; use App\Ninja\Repositories\AccountRepository; +use App\Models\LookupUser; use Auth; use Input; use Session; @@ -59,13 +60,13 @@ class AuthService $socialiteUser = Socialite::driver($provider)->user(); $providerId = self::getProviderId($provider); + $email = $socialiteUser->email; + $oauthUserId = $socialiteUser->id; + $name = Utils::splitName($socialiteUser->name); + if (Auth::check()) { $user = Auth::user(); $isRegistered = $user->registered; - - $email = $socialiteUser->email; - $oauthUserId = $socialiteUser->id; - $name = Utils::splitName($socialiteUser->name); $result = $this->accountRepo->updateUserFromOauth($user, $name[0], $name[1], $email, $providerId, $oauthUserId); if ($result === true) { @@ -81,6 +82,8 @@ class AuthService Session::flash('error', $result); } } else { + LookupUser::setServerByField('email', $email); + if ($user = $this->accountRepo->findUserByOauth($providerId, $socialiteUser->id)) { Auth::login($user, true); event(new UserLoggedIn());