mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Handle list filters from Contact Routes
This commit is contained in:
parent
2f401e3457
commit
89797b0991
@ -106,15 +106,23 @@ class InvoiceFilters extends QueryFilters
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the query by the users company ID
|
* Filters the query by the users company ID
|
||||||
|
*
|
||||||
|
* We need to ensure we are using the correct company ID
|
||||||
|
* as we could be hitting this from either the client or company auth guard
|
||||||
*
|
*
|
||||||
* @param $company_id The company Id
|
* @param $company_id The company Id
|
||||||
* @return Illuminate\Database\Query\Builder
|
* @return Illuminate\Database\Query\Builder
|
||||||
*/
|
*/
|
||||||
public function entityFilter()
|
public function entityFilter()
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
if(auth('contact')->user())
|
||||||
|
return $this->builder->whereCompanyId(auth('contact')->user()->company->id);
|
||||||
|
else
|
||||||
|
return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -76,6 +76,8 @@ abstract class QueryFilters
|
|||||||
|
|
||||||
$this->entityFilter();
|
$this->entityFilter();
|
||||||
|
|
||||||
|
$this->clientFilter();
|
||||||
|
|
||||||
foreach ($this->filters() as $name => $value) {
|
foreach ($this->filters() as $name => $value) {
|
||||||
if (! method_exists($this, $name)) {
|
if (! method_exists($this, $name)) {
|
||||||
continue;
|
continue;
|
||||||
@ -154,4 +156,18 @@ abstract class QueryFilters
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the query by the contact's client_id.
|
||||||
|
*
|
||||||
|
* -Can only be used on contact routes
|
||||||
|
*
|
||||||
|
* @param $client_id The client Id
|
||||||
|
* @param Illuminate\Database\Query\Builder
|
||||||
|
*/
|
||||||
|
public function clientFilter()
|
||||||
|
{
|
||||||
|
if(auth('contact')->user())
|
||||||
|
return $this->builder->whereClientId(auth('contact')->user()->client->id);
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Contact;
|
namespace App\Http\Controllers\Contact;
|
||||||
|
|
||||||
|
use App\Filters\InvoiceFilters;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Transformers\Contact\InvoiceTransformer;
|
use App\Transformers\Contact\InvoiceTransformer;
|
||||||
@ -39,10 +40,11 @@ class InvoiceController extends BaseController
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(InvoiceFilters $filters)
|
||||||
{
|
{
|
||||||
$invoices = Invoice::whereClientId(auth('contact')->user()->client->id);
|
//$invoices = Invoice::whereClientId(auth('contact')->user()->client->id);
|
||||||
//$invoices = Invoice::filter($filters);
|
|
||||||
|
$invoices = Invoice::filter($filters);
|
||||||
|
|
||||||
return $this->listResponse($invoices);
|
return $this->listResponse($invoices);
|
||||||
|
|
||||||
|
@ -47,13 +47,6 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
protected $entity_transformer = ClientContactLoginTransformer::class;
|
protected $entity_transformer = ClientContactLoginTransformer::class;
|
||||||
|
|
||||||
/**
|
|
||||||
* Where to redirect users after login.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $redirectTo = '/dashboard';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new controller instance.
|
* Create a new controller instance.
|
||||||
*
|
*
|
||||||
@ -64,22 +57,8 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Once the user is authenticated, we need to set
|
|
||||||
* the default company into a session variable
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* deprecated .1 API ONLY we don't need to set any session variables
|
|
||||||
*/
|
|
||||||
public function authenticated(Request $request, User $user) : void
|
|
||||||
{
|
|
||||||
//$this->setCurrentCompanyId($user->companies()->first()->account->default_company_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login via API
|
* Login via API
|
||||||
*
|
*
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App\Events\User\UserLoggedIn;
|
use App\Events\Contact\ContactLoggedIn;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\CompanyToken;
|
use App\Models\CompanyToken;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -43,9 +43,9 @@ class ContactTokenAuth
|
|||||||
|
|
||||||
//stateless, don't remember the contact.
|
//stateless, don't remember the contact.
|
||||||
auth()->guard('contact')->login($client_contact, false);
|
auth()->guard('contact')->login($client_contact, false);
|
||||||
|
|
||||||
//event(new UserLoggedIn($user)); //todo
|
|
||||||
|
|
||||||
|
event(new ContactLoggedIn($client_contact)); //todo
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
@ -117,20 +117,15 @@ class MultiDatabaseUserProvider implements UserProvider
|
|||||||
*/
|
*/
|
||||||
public function retrieveByCredentials(array $credentials)
|
public function retrieveByCredentials(array $credentials)
|
||||||
{
|
{
|
||||||
//Log::error('retrieving by credentials');
|
|
||||||
if (empty($credentials) ||
|
if (empty($credentials) ||
|
||||||
(count($credentials) === 1 &&
|
(count($credentials) === 1 &&
|
||||||
array_key_exists('password', $credentials))) {
|
array_key_exists('password', $credentials))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log::error('settings DB');
|
|
||||||
|
|
||||||
$this->setDefaultDatabase(false, $credentials['email'], false);
|
$this->setDefaultDatabase(false, $credentials['email'], false);
|
||||||
|
|
||||||
//Log::error('set DB');
|
|
||||||
|
|
||||||
|
|
||||||
// First we will add each credential element to the query as a where clause.
|
// First we will add each credential element to the query as a where clause.
|
||||||
// Then we can execute the query and, if we found a user, return it in a
|
// Then we can execute the query and, if we found a user, return it in a
|
||||||
// Eloquent User "model" that will be utilized by the Guard instances.
|
// Eloquent User "model" that will be utilized by the Guard instances.
|
||||||
@ -147,7 +142,7 @@ class MultiDatabaseUserProvider implements UserProvider
|
|||||||
$query->where($key, $value);
|
$query->where($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Log::error($query->count());
|
|
||||||
return $query->first();
|
return $query->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +157,7 @@ class MultiDatabaseUserProvider implements UserProvider
|
|||||||
{ Log::error('validateCredentials');
|
{ Log::error('validateCredentials');
|
||||||
|
|
||||||
$plain = $credentials['password'];
|
$plain = $credentials['password'];
|
||||||
//Log::error($plain);
|
|
||||||
return $this->hasher->check($plain, $user->getAuthPassword());
|
return $this->hasher->check($plain, $user->getAuthPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,16 +219,16 @@ class MultiDatabaseUserProvider implements UserProvider
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets correct database by variable
|
||||||
|
*/
|
||||||
private function setDefaultDatabase($id = false, $email = false, $token = false) : void
|
private function setDefaultDatabase($id = false, $email = false, $token = false) : void
|
||||||
{
|
{
|
||||||
//Log::error('setting DB');
|
|
||||||
//Log::error('model = '.$this->model);
|
|
||||||
|
|
||||||
foreach (MultiDB::getDbs() as $database) {
|
foreach (MultiDB::getDbs() as $database) {
|
||||||
$this->setDB($database);
|
|
||||||
|
|
||||||
// $query = $this->conn->table('users');
|
$this->setDB($database);
|
||||||
//
|
|
||||||
/** Make sure we hook into the correct guard class */
|
/** Make sure we hook into the correct guard class */
|
||||||
$query = $this->conn->table((new $this->model)->getTable());
|
$query = $this->conn->table((new $this->model)->getTable());
|
||||||
|
|
||||||
@ -245,8 +240,8 @@ class MultiDatabaseUserProvider implements UserProvider
|
|||||||
|
|
||||||
$user = $query->get();
|
$user = $query->get();
|
||||||
|
|
||||||
if (count($user) >= 1) {
|
if (count($user) >= 1)
|
||||||
//Log::error('found user, settings DB for EMAIL');
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,32 +249,35 @@ class MultiDatabaseUserProvider implements UserProvider
|
|||||||
|
|
||||||
if ($token)
|
if ($token)
|
||||||
{
|
{
|
||||||
Log::error('found user, settings DB for TOKEN');
|
|
||||||
|
|
||||||
$query->whereRaw("BINARY `token`= ?", $token);
|
$query->whereRaw("BINARY `token`= ?", $token);
|
||||||
|
|
||||||
$token = $query->get();
|
$token = $query->get();
|
||||||
|
|
||||||
if (count($token) >= 1) {
|
if (count($token) >= 1)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the database at runtime
|
||||||
|
*/
|
||||||
private function setDB($database)
|
private function setDB($database)
|
||||||
{
|
{
|
||||||
/** Get the database name we want to switch to*/
|
/** Get the database name we want to switch to*/
|
||||||
$db_name = config('database.connections.'.$database.'.database');
|
$db_name = config('database.connections.'.$database.'.database');
|
||||||
//$db_host = config("database.connections.".$database.".db_host");
|
|
||||||
|
|
||||||
/* This will set the default configuration for the request / session?*/
|
/* This will set the default configuration for the request / session?*/
|
||||||
config(['database.default' => $database]);
|
config(['database.default' => $database]);
|
||||||
|
|
||||||
/* Set the connection to complete the user authentication */
|
/* Set the connection to complete the user authentication */
|
||||||
//$this->conn = app('db')->connection(config("database.connections.database." . $database . "." . $db_name));
|
|
||||||
$this->conn = app('db')->connection(config('database.connections.database.'.$database));
|
$this->conn = app('db')->connection(config('database.connections.database.'.$database));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,7 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
Route::group(['middleware' => ['api_secret_check']], function () {
|
Route::group(['middleware' => ['api_secret_check']], function () {
|
||||||
|
|
||||||
//Route::post('api/v1/signup', 'AccountController@store')->name('signup.submit');
|
|
||||||
Route::post('api/v1/contact/login', 'Contact\LoginController@apiLogin');
|
Route::post('api/v1/contact/login', 'Contact\LoginController@apiLogin');
|
||||||
//Route::post('api/v1/oauth_login', 'Auth\LoginController@oauthApiLogin');
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user