diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 40ab67814b38..dd012a563473 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -41,20 +41,40 @@ class LoginController extends Controller $this->middleware('guest:user')->except('logout'); } + /** + * Once the user is authenticated, we need to set + * the default company into a session variable + * + * @return void + */ public function authenticated(Request $request, $user) { $this->setCurrentCompanyId($user->companies()->first()->account->default_company_id); } + /** + * Redirect the user to the provider authentication page + * + * @return void + */ public function redirectToProvider($provider) { return Socialite::driver($provider)->redirect(); } + /** + * Received the returning object from the provider + * which we will use to resolve the user + * + * @return redirect + */ public function handleProviderCallback($provider) { - $user = Socialite::driver('github')->user(); + $user = Socialite::driver($provider)->user(); + /** If user exists, redirect to dashboard */ + + /** If user does not exist, create account sequence */ dd($user); } } diff --git a/app/Models/Account.php b/app/Models/Account.php index 0e0ce2865273..9ad9ca859cfc 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Laracasts\Presenter\PresentableTrait; @@ -10,6 +11,7 @@ class Account extends BaseModel { use SoftDeletes; use PresentableTrait; + use MakesHash; /** * @var string diff --git a/app/Models/Client.php b/app/Models/Client.php index bc8d231bba04..8bd8bb300f39 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -15,7 +15,7 @@ class Client extends BaseModel protected $presenter = 'App\Models\Presenters\ClientPresenter'; - protected $appends = ['client_id']; + //protected $appends = ['client_id']; protected $guarded = [ 'id' diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 74e13a60ef19..bd20ee6aaf60 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -2,15 +2,19 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Hashids\Hashids; -use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; class ClientContact extends Authenticatable { use Notifiable; + use MakesHash; + + protected $appends = ['contact_id']; protected $guard = 'contact'; @@ -19,14 +23,8 @@ class ClientContact extends Authenticatable * * @var array */ - protected $fillable = [ - 'first_name', - 'last_name', - 'email', - 'password', - 'phone', - 'custom_value1', - 'custom_value2', + protected $guarded = [ + 'id', ]; /** @@ -38,6 +36,16 @@ class ClientContact extends Authenticatable 'password', 'remember_token', ]; + + public function getRouteKeyName() + { + return 'contact_id'; + } + + public function getContactIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } public function client() { diff --git a/app/Models/ClientLocation.php b/app/Models/ClientLocation.php index 5648b25f6e40..bcfcd357a223 100644 --- a/app/Models/ClientLocation.php +++ b/app/Models/ClientLocation.php @@ -2,9 +2,29 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class ClientLocation extends BaseModel { + use MakesHash; + public $timestamps = false; + + protected $appends = ['client_location_id']; + + public function getRouteKeyName() + { + return 'client_location_id'; + } + + public function getClientLocationIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } + + public function client() + { + return $this->belongsTo(Client::class); + } } diff --git a/app/Models/Company.php b/app/Models/Company.php index 1a715eb223ac..acdb55741aae 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -2,50 +2,40 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; use App\Models\Traits\AccountTrait; +use App\Utils\Traits\MakesHash; +use Illuminate\Database\Eloquent\Model; use Laracasts\Presenter\PresentableTrait; class Company extends BaseModel { use PresentableTrait; + use MakesHash; protected $presenter = 'App\Models\Presenters\CompanyPresenter'; - - protected $fillable = [ - - 'name', - 'address1', - 'address2', - 'city', - 'state', - 'postal_code', - 'country_id', - 'industry_id', - 'work_phone', - 'work_email', - 'language_id', - 'vat_number', - 'id_number', - 'tax_name1', - 'tax_rate1', - 'tax_name2', - 'tax_rate2', - 'website', - 'timezone_id', - 'currency_id', - + protected $guarded = [ + 'id', + 'company_id' ]; + //protected $appends = ['company_id']; + public function getRouteKeyName() + { + return 'company_id'; + } + + public function getCompanyIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } public function account() { return $this->belongsTo(Account::class); } - public function users() { return $this->hasMany(User::class); diff --git a/app/Models/Expense.php b/app/Models/Expense.php index d15be0828f42..7f42cb648e59 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -2,9 +2,26 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class Expense extends BaseModel { - // + use MakesHash; + + protected $guarded = [ + 'id', + ]; + + protected $appends = ['expense_id']; + + public function getRouteKeyName() + { + return 'expense_id'; + } + + public function getExpenseIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 55b8702ec895..c683c92e0f26 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -2,11 +2,28 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class Invoice extends BaseModel { - // + use MakesHash; + + protected $guarded = [ + 'id', + ]; + + protected $appends = ['invoice_id']; + + public function getRouteKeyName() + { + return 'invoice_id'; + } + + public function getInvoiceIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } public function invitations() { diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 08dbfd1fa36e..3b44618f53c8 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -2,9 +2,26 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class Payment extends BaseModel { - // + use MakesHash; + + protected $guarded = [ + 'id', + ]; + + protected $appends = ['payment_id']; + + public function getRouteKeyName() + { + return 'payment_id'; + } + + public function getPaymentIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 469aea198571..2f47c9b85954 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -2,9 +2,26 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class Product extends BaseModel { - // + use MakesHash; + + protected $guarded = [ + 'id', + ]; + + protected $appends = ['product_id']; + + public function getRouteKeyName() + { + return 'product_id'; + } + + public function getProductIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } } diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index d274b6c1abd9..693370613334 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -2,15 +2,28 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class Proposal extends BaseModel { - // + use MakesHash; - public function invitations() + protected $guarded = [ + 'id', + ]; + + protected $appends = ['proposal_id']; + + public function getRouteKeyName() { - $this->morphMany(Invitation::class, 'inviteable'); + return 'proposal_id'; } + public function getProposalIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } + + } diff --git a/app/Models/Task.php b/app/Models/Task.php index 60686d8c7d3d..b438eb84eb1d 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -2,9 +2,27 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class Task extends BaseModel { - // + use MakesHash; + + protected $guarded = [ + 'id', + ]; + + protected $appends = ['task_id']; + + public function getRouteKeyName() + { + return 'task_id'; + } + + public function getTaskIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } + } diff --git a/app/Models/TaxRate.php b/app/Models/TaxRate.php index 5f9c0c966a51..26f378e62a6e 100644 --- a/app/Models/TaxRate.php +++ b/app/Models/TaxRate.php @@ -2,9 +2,27 @@ namespace App\Models; +use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; class TaxRate extends BaseModel { - // + use MakesHash; + + protected $guarded = [ + 'id', + ]; + + protected $appends = ['tax_rate_id']; + + public function getRouteKeyName() + { + return 'tax_rate_id'; + } + + public function getTaxRateIdAttribute() + { + return $this->encodePrimaryKey($this->id); + } + } diff --git a/app/Models/User.php b/app/Models/User.php index 1b5596a4fb02..370ee7c33688 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,10 +4,11 @@ namespace App\Models; use App\Models\Traits\SetsUserSessionAttributes; use App\Models\Traits\UserTrait; -use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Notifications\Notifiable; +use App\Utils\Traits\MakesHash; use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; use Laracasts\Presenter\PresentableTrait; class User extends Authenticatable implements MustVerifyEmail @@ -15,7 +16,8 @@ class User extends Authenticatable implements MustVerifyEmail use Notifiable; use SoftDeletes; use PresentableTrait; - + use MakesHash; + protected $guard = 'user'; protected $dates = ['deleted_at']; diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 133a58fbdb84..e7da3000260c 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -31,6 +31,57 @@ class RouteServiceProvider extends ServiceProvider Route::bind('client', function ($value) { return \App\Models\Client::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); }); + + Route::bind('invoice', function ($value) { + return \App\Models\Invoice::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('payment', function ($value) { + return \App\Models\Payment::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('product', function ($value) { + return \App\Models\Product::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('company', function ($value) { + return \App\Models\Company::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('account', function ($value) { + return \App\Models\Account::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('client_contact', function ($value) { + return \App\Models\ClientContact::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('client_location', function ($value) { + return \App\Models\ClientLocation::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('expense', function ($value) { + return \App\Models\Expense::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('invitation', function ($value) { + return \App\Models\Invitation::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('task', function ($value) { + return \App\Models\Task::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('tax_rate', function ($value) { + return \App\Models\TaxRate::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + Route::bind('proposal', function ($value) { + return \App\Models\Proposal::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + }); + + + } /** diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 281ae013ddbd..7ebaad759e6c 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -52,6 +52,33 @@ + +