1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #5960 from turbo124/v5-develop

Fixes for orphan users with no tokens
This commit is contained in:
David Bomba 2021-06-08 18:31:11 +10:00 committed by GitHub
commit 222dbc302c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,15 +213,24 @@ class LoginController extends BaseController
if(!$cu->exists())
return response()->json(['message' => 'User not linked to any companies'], 403);
$cu->first()->account->companies->each(function ($company) use($cu, $request){
/* Ensure the user has a valid token */
$user->company_users->each(function ($company_user){
if($company->tokens()->where('is_system', true)->count() == 0)
{
CreateCompanyToken::dispatchNow($company, $cu->first()->user, $request->server('HTTP_USER_AGENT'));
if($company_user->tokens->count() == 0){
CreateCompanyToken::dispatchNow($company_user->company, $company_user->user, $request->server('HTTP_USER_AGENT'));
}
});
// $cu->first()->account->companies->each(function ($company) use($cu, $request){
// if($company->tokens()->where('is_system', true)->count() == 0)
// {
// CreateCompanyToken::dispatchNow($company, $cu->first()->user, $request->server('HTTP_USER_AGENT'));
// }
// });
return $this->timeConstrainedResponse($cu);