1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 06:32:40 +01:00
invoiceninja/app/Http/Middleware/TokenAuth.php
2019-04-18 16:11:37 +10:00

36 lines
781 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 {
return response()->json(json_encode(['message' => 'Invalid token'], JSON_PRETTY_PRINT) ,403);
}
return $next($request);
}
}