1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Http/Middleware/PasswordProtection.php
David Bomba f57339f185
Fixes and Refactors for Invoice Emails. (#3339)
* Working on emailing invoices

* Working on emailing and displaying email

* Working on emailing and displaying email

* Email invoices

* Fixes for html emails

* Ensure valid client prior to store

* Ensure client exists when storing an entity

* Update variable name send -> send_email for client_contacts

* Mailable download files

* Extend timeouts of password protected routes when a protected route is hit

* Add default portal design to company settings

* Minor fixes

* Fixes for Tests

* Fixes for invoicing emails

* Refactors for InvoiceEmail

* Implement abstractservice

* Refactors for services

* Refactors for emails

* Fixes for Invoice Emails
2020-02-17 20:37:44 +11:00

61 lines
1.6 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Middleware;
use App\Libraries\MultiDB;
use App\Models\CompanyToken;
use Closure;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class PasswordProtection
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$error = [
'message' => 'Invalid Password',
'errors' => []
];
if ($request->header('X-API-PASSWORD')) {
if (!Hash::check($request->header('X-API-PASSWORD'), auth()->user()->password)) {
return response()->json($error, 403);
}
} elseif (Cache::get(auth()->user()->email."_logged_in")) {
Cache::pull(auth()->user()->email."_logged_in");
Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10));
return $next($request);
} else {
$error = [
'message' => 'Access denied',
'errors' => []
];
return response()->json($error, 412);
}
Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10));
return $next($request);
}
}