mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
38 lines
820 B
PHP
38 lines
820 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\CompanyToken;
|
|
use App\Models\User;
|
|
use Closure;
|
|
|
|
class TokenAuth
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next)
|
|
{
|
|
|
|
if( $request->header('X-API-TOKEN') && ($user = CompanyToken::whereRaw("BINARY `token`= ?",[$request->header('X-API-TOKEN')])->first()->user ) )
|
|
{
|
|
//$user->with('company');
|
|
|
|
auth()->login($user);
|
|
|
|
}
|
|
else {
|
|
|
|
$error['error'] = ['message' => 'Invalid token'];
|
|
|
|
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|