Handle edge case where removed user tries to log into the system

This commit is contained in:
David Bomba 2022-05-04 08:39:54 +10:00
parent 352a1fc1c0
commit 0ae42195b2

View File

@ -323,6 +323,9 @@ class LoginController extends BaseController
$cu = CompanyUser::query()
->where('user_id', $company_token->user_id);
if($cu->count() == 0)
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
$cu->first()->account->companies->each(function ($company) use($cu, $request){
if($company->tokens()->where('is_system', true)->count() == 0)
@ -393,6 +396,8 @@ class LoginController extends BaseController
$cu = CompanyUser::query()
->where('user_id', auth()->user()->id);
if($cu->count() == 0)
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
$truth = app()->make(TruthSource::class);
$truth->setCompanyUser($cu->first());
@ -444,6 +449,9 @@ class LoginController extends BaseController
$cu = CompanyUser::query()
->where('user_id', auth()->user()->id);
if($cu->count() == 0)
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
$truth = app()->make(TruthSource::class);
$truth->setCompanyUser($cu->first());
$truth->setUser($existing_login_user);
@ -499,6 +507,9 @@ class LoginController extends BaseController
$cu = CompanyUser::query()
->where('user_id', auth()->user()->id);
if($cu->count() == 0)
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
$truth = app()->make(TruthSource::class);
$truth->setCompanyUser($cu->first());
$truth->setUser($existing_login_user);
@ -558,6 +569,8 @@ class LoginController extends BaseController
$cu = CompanyUser::whereUserId(auth()->user()->id);
if($cu->count() == 0)
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
$truth = app()->make(TruthSource::class);
$truth->setCompanyUser($cu->first());