Enable invoice emailing
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Clarkeash\Doorman\Exceptions\{DoormanException,ExpiredInviteCode};
|
||||
use Clarkeash\Doorman\Facades\Doorman;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
||||
|
||||
@@ -14,7 +17,8 @@ class UserHomeController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
// Route protection is in routes.web
|
||||
// $this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,6 +69,32 @@ class UserHomeController extends Controller
|
||||
return PDF::loadView('u.invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the user to down an invoice by providing a link in email
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @param string $code
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
*/
|
||||
public function invoice_pdf_email(Invoice $o,string $code)
|
||||
{
|
||||
try {
|
||||
Doorman::redeem($code,$o->account->user->email);
|
||||
|
||||
} catch (ExpiredInviteCode $e) {
|
||||
Log::alert(sprintf('User is using an expired token for invoice [%s] using [%s]',$o->id,$code));
|
||||
|
||||
return redirect()->to('/login');
|
||||
|
||||
} catch (DoormanException $e) {
|
||||
Log::alert(sprintf('An attempt to read invoice id [%s] using [%s]',$o->id,$code));
|
||||
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $this->invoice_pdf($o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to redirect to the old site, when functions are not available in this one.
|
||||
*
|
||||
|
Reference in New Issue
Block a user