mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #5797 from turbo124/v5-develop
Fixes for MultiDB UserController
This commit is contained in:
commit
d01d460a58
@ -181,14 +181,16 @@ class BillingPortalPurchase extends Component
|
|||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
$contact = ClientContact::where('email', $this->email)->first();
|
$contact = ClientContact::where('email', $this->email)
|
||||||
|
->where('company_id', $this->subscription->company_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
if ($contact && $this->steps['existing_user'] === false) {
|
if ($contact && $this->steps['existing_user'] === false) {
|
||||||
return $this->steps['existing_user'] = true;
|
return $this->steps['existing_user'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($contact && $this->steps['existing_user']) {
|
if ($contact && $this->steps['existing_user']) {
|
||||||
$attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password]);
|
$attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password, 'company_id' => $this->subscription->company_id]);
|
||||||
|
|
||||||
return $attempt
|
return $attempt
|
||||||
? $this->getPaymentMethods($contact)
|
? $this->getPaymentMethods($contact)
|
||||||
|
@ -49,7 +49,6 @@ class TokenAuth
|
|||||||
| us to decouple a $user and their attached companies completely.
|
| us to decouple a $user and their attached companies completely.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
$user->setCompany($company_token->company);
|
|
||||||
|
|
||||||
app('queue')->createPayloadUsing(function () use ($company_token) {
|
app('queue')->createPayloadUsing(function () use ($company_token) {
|
||||||
return ['db' => $company_token->company->db];
|
return ['db' => $company_token->company->db];
|
||||||
@ -67,6 +66,7 @@ class TokenAuth
|
|||||||
|
|
||||||
//stateless, don't remember the user.
|
//stateless, don't remember the user.
|
||||||
auth()->login($user, false);
|
auth()->login($user, false);
|
||||||
|
auth()->user()->setCompany($company_token->company);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$error = [
|
$error = [
|
||||||
|
@ -159,8 +159,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function setCompany($company)
|
public function setCompany($company)
|
||||||
{
|
{
|
||||||
// config(['ninja.company_id' => $company->id]);
|
|
||||||
|
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,16 +168,17 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
public function getCompany()
|
public function getCompany()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (request()->header('X-API-TOKEN')) {
|
if ($this->company){
|
||||||
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
|
|
||||||
|
|
||||||
return $company_token->company;
|
|
||||||
}
|
|
||||||
elseif ($this->company){
|
|
||||||
|
|
||||||
return $this->company;
|
return $this->company;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
elseif (request()->header('X-API-TOKEN')) {
|
||||||
|
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
|
||||||
|
|
||||||
|
return $company_token->company;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// return false;
|
// return false;
|
||||||
throw new \Exception('No Company Found');
|
throw new \Exception('No Company Found');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user