mirror of
https://github.com/crater-invoice/crater.git
synced 2025-12-15 09:52:55 -05:00
build version 400
This commit is contained in:
43
app/Http/Controllers/V1/Mobile/AuthController.php
Normal file
43
app/Http/Controllers/V1/Mobile/AuthController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Controllers\V1\Mobile;
|
||||
|
||||
use Crater\Http\Controllers\Controller;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|email',
|
||||
'password' => 'required',
|
||||
'device_name' => 'required',
|
||||
]);
|
||||
|
||||
$user = User::where('email', $request->username)->first();
|
||||
|
||||
if (! $user || ! Hash::check($request->password, $user->password)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => ['The provided credentials are incorrect.'],
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'type' => 'Bearer',
|
||||
'token' => $user->createToken($request->device_name)->plainTextToken
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$request->user()->currentAccessToken()->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Controllers\V1\Mobile\Customer;
|
||||
|
||||
use Barryvdh\DomPDF\PDF;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateTemplate;
|
||||
use Crater\Http\Controllers\Controller;
|
||||
use Crater\Mail\EstimateViewedMail;
|
||||
use Crater\Models\User;
|
||||
|
||||
class EstimatePdfController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function __invoke(Estimate $estimate)
|
||||
{
|
||||
if ($estimate && ($estimate->status == Estimate::STATUS_SENT || $estimate->status == Estimate::STATUS_DRAFT)) {
|
||||
$estimate->status = Estimate::STATUS_VIEWED;
|
||||
$estimate->save();
|
||||
$notifyEstimateViewed = CompanySetting::getSetting(
|
||||
'notify_estimate_viewed',
|
||||
$estimate->company_id
|
||||
);
|
||||
|
||||
if ($notifyEstimateViewed == 'YES') {
|
||||
$data['estimate'] = Estimate::findOrFail($estimate->id)->toArray();
|
||||
$data['user'] = User::find($estimate->user_id)->toArray();
|
||||
$notificationEmail = CompanySetting::getSetting(
|
||||
'notification_email',
|
||||
$estimate->company_id
|
||||
);
|
||||
|
||||
\Mail::to($notificationEmail)->send(new EstimateViewedMail($data));
|
||||
}
|
||||
}
|
||||
|
||||
return $estimate->getGeneratedPDFOrStream('estimate');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Controllers\V1\Mobile\Customer;
|
||||
|
||||
use Barryvdh\DomPDF\PDF;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Http\Controllers\Controller;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceTemplate;
|
||||
use Crater\Mail\InvoiceViewedMail;
|
||||
use Crater\Models\User;
|
||||
|
||||
class InvoicePdfController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function __invoke(Invoice $invoice)
|
||||
{
|
||||
if ($invoice && ($invoice->status == Invoice::STATUS_SENT || $invoice->status == Invoice::STATUS_DRAFT)) {
|
||||
$invoice->status = Invoice::STATUS_VIEWED;
|
||||
$invoice->viewed = true;
|
||||
$invoice->save();
|
||||
$notifyInvoiceViewed = CompanySetting::getSetting(
|
||||
'notify_invoice_viewed',
|
||||
$invoice->company_id
|
||||
);
|
||||
|
||||
if ($notifyInvoiceViewed == 'YES') {
|
||||
$data['invoice'] = Invoice::findOrFail($invoice->id)->toArray();
|
||||
$data['user'] = User::find($invoice->user_id)->toArray();
|
||||
$notificationEmail = CompanySetting::getSetting(
|
||||
'notification_email',
|
||||
$invoice->company_id
|
||||
);
|
||||
|
||||
\Mail::to($notificationEmail)->send(new InvoiceViewedMail($data));
|
||||
}
|
||||
}
|
||||
|
||||
return $invoice->getGeneratedPDFOrStream('invoice');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user