mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
commit
53bf247ebc
@ -31,6 +31,7 @@ use App\Models\User;
|
|||||||
use App\Transformers\CompanyUserTransformer;
|
use App\Transformers\CompanyUserTransformer;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
|
use App\Utils\Traits\User\LoginCache;
|
||||||
use Google_Client;
|
use Google_Client;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -55,6 +56,7 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
use AuthenticatesUsers;
|
use AuthenticatesUsers;
|
||||||
use UserSessionAttributes;
|
use UserSessionAttributes;
|
||||||
|
use LoginCache;
|
||||||
|
|
||||||
protected $entity_type = CompanyUser::class;
|
protected $entity_type = CompanyUser::class;
|
||||||
|
|
||||||
@ -178,8 +180,7 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
event(new UserLoggedIn($user, $user->account->default_company, Ninja::eventVars($user->id)));
|
event(new UserLoggedIn($user, $user->account->default_company, Ninja::eventVars($user->id)));
|
||||||
|
|
||||||
//if user has 2fa enabled - lets check this now:
|
//2FA
|
||||||
|
|
||||||
if($user->google_2fa_secret && $request->has('one_time_password'))
|
if($user->google_2fa_secret && $request->has('one_time_password'))
|
||||||
{
|
{
|
||||||
$google2fa = new Google2FA();
|
$google2fa = new Google2FA();
|
||||||
@ -203,14 +204,7 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
$user->setCompany($user->account->default_company);
|
$user->setCompany($user->account->default_company);
|
||||||
|
|
||||||
$timeout = $user->company()->default_password_timeout;
|
$this->setLoginCache($user);
|
||||||
|
|
||||||
if($timeout == 0)
|
|
||||||
$timeout = 30*60*1000*1000;
|
|
||||||
else
|
|
||||||
$timeout = $timeout/1000;
|
|
||||||
|
|
||||||
Cache::put($user->hashed_id.'_'.$user->account_id.'_logged_in', Str::random(64), $timeout);
|
|
||||||
|
|
||||||
$cu = CompanyUser::query()
|
$cu = CompanyUser::query()
|
||||||
->where('user_id', auth()->user()->id);
|
->where('user_id', auth()->user()->id);
|
||||||
@ -228,7 +222,7 @@ class LoginController extends BaseController
|
|||||||
});
|
});
|
||||||
|
|
||||||
return $this->timeConstrainedResponse($cu);
|
return $this->timeConstrainedResponse($cu);
|
||||||
// return $this->listResponse($cu);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -362,14 +356,7 @@ class LoginController extends BaseController
|
|||||||
Auth::login($existing_user, true);
|
Auth::login($existing_user, true);
|
||||||
$existing_user->setCompany($existing_user->account->default_company);
|
$existing_user->setCompany($existing_user->account->default_company);
|
||||||
|
|
||||||
$timeout = $existing_user->company()->default_password_timeout;
|
$this->setLoginCache($existing_user);
|
||||||
|
|
||||||
if($timeout == 0)
|
|
||||||
$timeout = 30*60*1000*1000;
|
|
||||||
else
|
|
||||||
$timeout = $timeout/1000;
|
|
||||||
|
|
||||||
Cache::put($existing_user->hashed_id.'_'.$existing_user->account_id.'_logged_in', Str::random(64), $timeout);
|
|
||||||
|
|
||||||
$cu = CompanyUser::query()
|
$cu = CompanyUser::query()
|
||||||
->where('user_id', auth()->user()->id);
|
->where('user_id', auth()->user()->id);
|
||||||
@ -392,21 +379,13 @@ class LoginController extends BaseController
|
|||||||
Auth::login($existing_login_user, true);
|
Auth::login($existing_login_user, true);
|
||||||
$existing_login_user->setCompany($existing_login_user->account->default_company);
|
$existing_login_user->setCompany($existing_login_user->account->default_company);
|
||||||
|
|
||||||
$timeout = $existing_login_user->company()->default_password_timeout;
|
$this->setLoginCache($existing_login_user);
|
||||||
|
|
||||||
if($timeout == 0)
|
|
||||||
$timeout = 30*60*1000*1000;
|
|
||||||
else
|
|
||||||
$timeout = $timeout/1000;
|
|
||||||
|
|
||||||
Cache::put($existing_login_user->hashed_id.'_'.$existing_login_user->account_id.'_logged_in', Str::random(64), $timeout);
|
|
||||||
|
|
||||||
auth()->user()->update([
|
auth()->user()->update([
|
||||||
'oauth_user_id' => $google->harvestSubField($user),
|
'oauth_user_id' => $google->harvestSubField($user),
|
||||||
'oauth_provider_id'=> 'google',
|
'oauth_provider_id'=> 'google',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$cu = CompanyUser::query()
|
$cu = CompanyUser::query()
|
||||||
->where('user_id', auth()->user()->id);
|
->where('user_id', auth()->user()->id);
|
||||||
|
|
||||||
@ -447,14 +426,7 @@ class LoginController extends BaseController
|
|||||||
auth()->user()->email_verified_at = now();
|
auth()->user()->email_verified_at = now();
|
||||||
auth()->user()->save();
|
auth()->user()->save();
|
||||||
|
|
||||||
$timeout = auth()->user()->company()->default_password_timeout;
|
$this->setLoginCache(auth()->user());
|
||||||
|
|
||||||
if($timeout == 0)
|
|
||||||
$timeout = 30*60*1000*1000;
|
|
||||||
else
|
|
||||||
$timeout = $timeout/1000;
|
|
||||||
|
|
||||||
Cache::put(auth()->user()->hashed_id.'_'.auth()->user()->account_id.'_logged_in', Str::random(64), $timeout);
|
|
||||||
|
|
||||||
$cu = CompanyUser::whereUserId(auth()->user()->id);
|
$cu = CompanyUser::whereUserId(auth()->user()->id);
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class ImportCustomers
|
|||||||
}
|
}
|
||||||
|
|
||||||
nlog("inserting a customer");
|
nlog("inserting a customer");
|
||||||
nlog($customer);
|
//nlog($customer);
|
||||||
|
|
||||||
$client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id);
|
$client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id);
|
||||||
|
|
||||||
|
35
app/Utils/Traits/User/LoginCache.php
Normal file
35
app/Utils/Traits/User/LoginCache.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Utils\Traits\User;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
trait LoginCache
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setLoginCache($user)
|
||||||
|
{
|
||||||
|
|
||||||
|
$timeout = $user->company()->default_password_timeout;
|
||||||
|
|
||||||
|
if($timeout == 0)
|
||||||
|
$timeout = 30*60*1000*1000;
|
||||||
|
else
|
||||||
|
$timeout = $timeout/1000;
|
||||||
|
|
||||||
|
Cache::put($user->hashed_id.'_'.$user->account_id.'_logged_in', Str::random(64), $timeout);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user