Move User model to Models/

This commit is contained in:
Deon George 2021-06-29 13:18:52 +10:00
parent 8899ade36b
commit 638472fb4f
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
29 changed files with 94 additions and 102 deletions

View File

@ -5,11 +5,10 @@ namespace App\Classes\External\Accounting;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use QuickBooksOnline\API\Data\IPPCustomer; use QuickBooksOnline\API\Data\IPPCustomer;
use App\User;
use App\Classes\External\Accounting as Base; use App\Classes\External\Accounting as Base;
use App\Models\User;
class Quickbooks extends Base class Quickbooks extends Base
{ {

View File

@ -2,15 +2,13 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Classes\External\Accounting\Quickbooks;
use App\Models\Account;
use App\Models\External\Integrations;
use QuickBooksOnline\API\Data\IPPEmailAddress; use QuickBooksOnline\API\Data\IPPEmailAddress;
use QuickBooksOnline\API\Data\IPPPhysicalAddress; use QuickBooksOnline\API\Data\IPPPhysicalAddress;
use App\Classes\External\Accounting\Quickbooks;
use App\Models\{Account,External\Integrations,User};
class QuickAccounts extends Command class QuickAccounts extends Command
{ {
/** /**

View File

@ -6,7 +6,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use App\Mail\TestEmail as MailTest; use App\Mail\TestEmail as MailTest;
use App\User; use App\Models\User;
class TestEmail extends Command class TestEmail extends Command
{ {

View File

@ -4,8 +4,7 @@ namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Models\Account; use App\Models\{Account,User};
use App\User;
class UserAccountMerge extends Command class UserAccountMerge extends Command
{ {

View File

@ -2,12 +2,13 @@
namespace App\Http\Controllers\Auth; namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Foundation\Auth\RegistersUsers;
use App\Models\User;
class RegisterController extends Controller class RegisterController extends Controller
{ {
/* /*
@ -58,13 +59,13 @@ class RegisterController extends Controller
]); ]);
} }
/** /**
* Create a new user instance after a valid registration. * Create a new user instance after a valid registration.
* *
* @param array $data * @param array $data
* @return \App\User * @return User
*/ */
protected function create(array $data) protected function create(array $data): User
{ {
$fields = [ $fields = [
'name' => $data['name'], 'name' => $data['name'],

View File

@ -7,13 +7,13 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Facades\Socialite;
use App\Providers\RouteServiceProvider;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Mail\SocialLink; use App\Mail\SocialLink;
use App\Models\Oauth; use App\Models\Oauth;
use App\Models\AccountOauth; use App\Models\AccountOauth;
use App\User; use App\Models\User;
use App\Providers\RouteServiceProvider;
class SocialLoginController extends Controller class SocialLoginController extends Controller
{ {
@ -31,18 +31,15 @@ class SocialLoginController extends Controller
// See if this user has connected and linked previously // See if this user has connected and linked previously
$aoo = $oo->accounts->where('userid',$openiduser->id); $aoo = $oo->accounts->where('userid',$openiduser->id);
if ($aoo->count() == 1) if ($aoo->count() == 1) {
{
$aoo = $aoo->first(); $aoo = $aoo->first();
if ((is_null($user=$aoo->user) AND (is_null($aoo->account) OR is_null($user=$aoo->account->user))) OR ! $user->active) if ((is_null($user=$aoo->user) AND (is_null($aoo->account) OR is_null($user=$aoo->account->user))) OR ! $user->active) {
{
if (! $user) { if (! $user) {
$user = User::where('email',$openiduser->email)->first(); $user = User::where('email',$openiduser->email)->first();
} }
if (! $user OR ! $user->active) if (! $user OR ! $user->active) {
{
return redirect('/login')->with('error','Invalid account, or account inactive, please contact an admin.'); return redirect('/login')->with('error','Invalid account, or account inactive, please contact an admin.');
} }
@ -61,8 +58,7 @@ class SocialLoginController extends Controller
$uo = User::active()->where('email',$openiduser->email); $uo = User::active()->where('email',$openiduser->email);
// See if their is an account with this email address // See if their is an account with this email address
if ($uo->count() == 1) if ($uo->count() == 1) {
{
$aoo = new AccountOauth; $aoo = new AccountOauth;
$aoo->userid = $openiduser->id; $aoo->userid = $openiduser->id;
$aoo->oauth_data = $openiduser->user; $aoo->oauth_data = $openiduser->user;
@ -70,7 +66,7 @@ class SocialLoginController extends Controller
return $this->link($provider,$aoo,$uo->first()); return $this->link($provider,$aoo,$uo->first());
// If there are too many users, then we have a problem // If there are too many users, then we have a problem
} elseif ($uo->count() > 1) { } elseif ($uo->count() > 1) {
return redirect('/login')->with('error','Seems you have multiple accounts, please contact an admin.'); return redirect('/login')->with('error','Seems you have multiple accounts, please contact an admin.');

View File

@ -10,15 +10,21 @@ use Illuminate\Support\Facades\Log;
use Illuminate\View\View; use Illuminate\View\View;
use Barryvdh\Snappy\Facades\SnappyPdf as PDF; use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
use App\Models\{Invoice,Service}; use App\Models\{Invoice,Service,User};
use App\User;
/**
* Class HomeController
* This controller is the logged in users home page
*
* The methods to this controller should be projected by the route
*
* @package App\Http\Controllers
*/
class HomeController extends Controller class HomeController extends Controller
{ {
public function __construct() public function __construct()
{ {
// Route protection is in routes.web $this->middleware('auth');
// $this->middleware('auth');
} }
/** /**
@ -26,9 +32,10 @@ class HomeController extends Controller
* *
* @return Factory|View * @return Factory|View
*/ */
public function home(User $o=NULL): View public function home(User $o): View
{ {
if ($o) // If we are passed a user to view, we'll open up their home page.
if ($o->exists)
return View('u.home',['o'=>$o]); return View('u.home',['o'=>$o]);
// If User was null, then test and see what type of logged on user we have // If User was null, then test and see what type of logged on user we have
@ -43,7 +50,7 @@ class HomeController extends Controller
return View('r.home',['o'=>$o]); return View('r.home',['o'=>$o]);
default: default:
abort(500,'Unknown role: '.$o->role()); abort(404,'Unknown role: '.$o->role());
} }
} }

View File

@ -10,11 +10,15 @@ use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Mail\OrderRequest; use App\Mail\OrderRequest;
use App\Models\{Account,Product,Service}; use App\Models\{Account,Product,Service,User};
use App\User;
class OrderController extends Controller class OrderController extends Controller
{ {
public function __construct()
{
$this->middleware('auth');
}
public function index() public function index()
{ {
return view('order'); return view('order');
@ -122,4 +126,4 @@ class OrderController extends Controller
return view('order_received',['o'=>$so]); return view('order_received',['o'=>$so]);
} }
} }

View File

@ -6,8 +6,7 @@ use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\User; use App\Models\{Account,Invoice,Service,Service\Adsl,User};
use App\Models\{Account,Invoice,Service,Service\Adsl};
class SearchController extends Controller class SearchController extends Controller
{ {

View File

@ -2,8 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth; use App\Models\User;
use App\User;
class UserServicesController extends Controller class UserServicesController extends Controller
{ {

View File

@ -3,9 +3,9 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Closure; use Closure;
use Config;
use View;
use App\Models\Site; use App\Models\Site;
@ -30,15 +30,11 @@ class SetSite
$so = new Site; $so = new Site;
if ($so->getTable() AND Schema::hasTable($so->getTable())) if ($so->getTable() AND Schema::hasTable($so->getTable()))
{ $so = Site::where('url',$request->root())->first();
$so = Site::where('url',$request->root())
->first();
}
// If we dont exist, we'll return a fake model. // If we dont exist, we'll return a fake model.
if (! $so or ! $so->exists) { if ((! $so) || (! $so->exists))
$so = (new Site)->sample(); $so = (new Site)->sample();
}
// Set who we are in SETUP. // Set who we are in SETUP.
Config::set('SITE_SETUP',$so); Config::set('SITE_SETUP',$so);

View File

@ -6,8 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use App\Models\AccountOauth; use App\Models\{AccountOauth,User};
use App\User;
class SocialLink extends Mailable class SocialLink extends Mailable
{ {

View File

@ -7,7 +7,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use App\User; use App\Models\User;
class TestEmail extends Mailable class TestEmail extends Mailable
{ {

View File

@ -66,7 +66,7 @@ class Account extends Model
public function user() public function user()
{ {
return $this->belongsTo(\App\User::class); return $this->belongsTo(User::class);
} }
/** SCOPES */ /** SCOPES */

View File

@ -4,7 +4,6 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Traits\NextKey; use App\Traits\NextKey;
class AccountOauth extends Model class AccountOauth extends Model

View File

@ -27,6 +27,6 @@ class Country extends Model
*/ */
public function users() public function users()
{ {
return $this->hasMany(\App\User::class); return $this->hasMany(User::class);
} }
} }

View File

@ -4,7 +4,7 @@ namespace App\Models\External;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\User; use App\Models\User;
class Integrations extends Model class Integrations extends Model
{ {

View File

@ -4,7 +4,6 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Traits\NextKey; use App\Traits\NextKey;
class Oauth extends Model class Oauth extends Model

View File

@ -4,8 +4,7 @@ namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Auth\Access\HandlesAuthorization;
use App\Models\Account; use App\Models\{Account,User};
use App\User;
class AccountPolicy class AccountPolicy
{ {

View File

@ -4,8 +4,7 @@ namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Auth\Access\HandlesAuthorization;
use App\Models\Invoice; use App\Models\{Invoice,User};
use App\User;
class InvoicePolicy class InvoicePolicy
{ {
@ -14,8 +13,8 @@ class InvoicePolicy
/** /**
* Determine whether the user can view the service. * Determine whether the user can view the service.
* *
* @param \App\User $user * @param User $user
* @param Invoice $o * @param Invoice $o
* @return mixed * @return mixed
*/ */
public function view(User $user, Invoice $o) public function view(User $user, Invoice $o)
@ -33,7 +32,7 @@ class InvoicePolicy
/** /**
* Determine whether the user can create services. * Determine whether the user can create services.
* *
* @param \App\User $user * @param User $user
* @return mixed * @return mixed
*/ */
public function create(User $user) public function create(User $user)
@ -44,8 +43,8 @@ class InvoicePolicy
/** /**
* Determine whether the user can update the service. * Determine whether the user can update the service.
* *
* @param \App\User $user * @param User $user
* @param Invoice $o * @param Invoice $o
* @return mixed * @return mixed
*/ */
public function update(User $user, Invoice $o) public function update(User $user, Invoice $o)
@ -56,8 +55,8 @@ class InvoicePolicy
/** /**
* Determine whether the user can delete the service. * Determine whether the user can delete the service.
* *
* @param \App\User $user * @param User $user
* @param Invoice $o * @param Invoice $o
* @return mixed * @return mixed
*/ */
public function delete(User $user, Invoice $o) public function delete(User $user, Invoice $o)
@ -68,8 +67,8 @@ class InvoicePolicy
/** /**
* Determine whether the user can restore the service. * Determine whether the user can restore the service.
* *
* @param \App\User $user * @param User $user
* @param Invoice $o * @param Invoice $o
* @return mixed * @return mixed
*/ */
public function restore(User $user, Invoice $o) public function restore(User $user, Invoice $o)
@ -80,8 +79,8 @@ class InvoicePolicy
/** /**
* Determine whether the user can permanently delete the service. * Determine whether the user can permanently delete the service.
* *
* @param \App\User $user * @param User $user
* @param Invoice $o * @param Invoice $o
* @return mixed * @return mixed
*/ */
public function forceDelete(User $user, Invoice $o) public function forceDelete(User $user, Invoice $o)

View File

@ -4,8 +4,7 @@ namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Auth\Access\HandlesAuthorization;
use App\Models\Service; use App\Models\{Service,User};
use App\User;
class ServicePolicy class ServicePolicy
{ {
@ -14,8 +13,8 @@ class ServicePolicy
/** /**
* Determine whether the user can view the service. * Determine whether the user can view the service.
* *
* @param \App\User $user * @param User $user
* @param Service $o * @param Service $o
* @return mixed * @return mixed
*/ */
public function view(User $user, Service $o) public function view(User $user, Service $o)
@ -33,7 +32,7 @@ class ServicePolicy
/** /**
* Determine whether the user can create services. * Determine whether the user can create services.
* *
* @param \App\User $user * @param User $user
* @return mixed * @return mixed
*/ */
public function create(User $user) public function create(User $user)
@ -46,6 +45,7 @@ class ServicePolicy
* *
* @param User $user * @param User $user
* @param Service $o * @param Service $o
* @param string $next
* @return bool * @return bool
*/ */
public function progress(User $user, Service $o,string $next) public function progress(User $user, Service $o,string $next)
@ -56,8 +56,8 @@ class ServicePolicy
/** /**
* Determine whether the user can update the service. * Determine whether the user can update the service.
* *
* @param \App\User $user * @param User $user
* @param Service $o * @param Service $o
* @return mixed * @return mixed
*/ */
public function update(User $user, Service $o) public function update(User $user, Service $o)
@ -68,8 +68,8 @@ class ServicePolicy
/** /**
* Determine whether the user can delete the service. * Determine whether the user can delete the service.
* *
* @param \App\User $user * @param User $user
* @param Service $o * @param Service $o
* @return mixed * @return mixed
*/ */
public function delete(User $user, Service $o) public function delete(User $user, Service $o)
@ -80,8 +80,8 @@ class ServicePolicy
/** /**
* Determine whether the user can restore the service. * Determine whether the user can restore the service.
* *
* @param \App\User $user * @param User $user
* @param Service $o * @param Service $o
* @return mixed * @return mixed
*/ */
public function restore(User $user, Service $o) public function restore(User $user, Service $o)
@ -92,8 +92,8 @@ class ServicePolicy
/** /**
* Determine whether the user can permanently delete the service. * Determine whether the user can permanently delete the service.
* *
* @param \App\User $user * @param User $user
* @param Service $o * @param Service $o
* @return mixed * @return mixed
*/ */
public function forceDelete(User $user, Service $o) public function forceDelete(User $user, Service $o)

View File

@ -4,7 +4,7 @@ namespace App\Policies;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Auth\Access\HandlesAuthorization;
use App\User; use App\Models\User;
class UserPolicy class UserPolicy
{ {

View File

@ -15,7 +15,6 @@ use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Leenooks\Carbon; use Leenooks\Carbon;
use App\User;
use App\Traits\NextKey; use App\Traits\NextKey;
class Service extends Model class Service extends Model

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App; namespace App\Models;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
@ -14,7 +14,6 @@ use Leenooks\Traits\UserSwitch;
use Spinen\QuickBooks\HasQuickBooksToken; use Spinen\QuickBooks\HasQuickBooksToken;
use App\Notifications\ResetPassword as ResetPasswordNotification; use App\Notifications\ResetPassword as ResetPasswordNotification;
use App\Models\{Invoice,Payment,Site,Service};
class User extends Authenticatable class User extends Authenticatable
{ {
@ -82,7 +81,7 @@ class User extends Authenticatable
*/ */
public function accounts() public function accounts()
{ {
return $this->hasMany(Models\Account::class); return $this->hasMany(Account::class);
} }
/** /**
@ -112,7 +111,7 @@ class User extends Authenticatable
*/ */
public function language() public function language()
{ {
return $this->belongsTo(Models\Language::class); return $this->belongsTo(Language::class);
} }
/** /**
@ -122,7 +121,7 @@ class User extends Authenticatable
*/ */
public function invoices() public function invoices()
{ {
return $this->hasManyThrough(Models\Invoice::class,Models\Account::class); return $this->hasManyThrough(Invoice::class,Account::class);
} }
/** /**
@ -132,7 +131,7 @@ class User extends Authenticatable
*/ */
public function payments() public function payments()
{ {
return $this->hasManyThrough(Models\Payment::class,Models\Account::class); return $this->hasManyThrough(Payment::class,Account::class);
} }
/** /**
@ -142,7 +141,7 @@ class User extends Authenticatable
*/ */
public function services() public function services()
{ {
return $this->hasManyThrough(Models\Service::class,Models\Account::class); return $this->hasManyThrough(Service::class,Account::class);
} }
/** /**
@ -268,7 +267,7 @@ class User extends Authenticatable
public function getSwitchUrlAttribute() public function getSwitchUrlAttribute()
{ {
return sprintf('<a href="/a/switch/start/%s"><i class="fa fa-external-link"></i></a>',$this->id); return sprintf('<a href="/a/switch/start/%s"><i class="fas fa-external-link-alt"></i></a>',$this->id);
} }
public function getUserIdAttribute() public function getUserIdAttribute()
@ -293,6 +292,7 @@ class User extends Authenticatable
/** SCOPES */ /** SCOPES */
// @todo use trait
public function scopeActive() public function scopeActive()
{ {
return $this->where('active',TRUE); return $this->where('active',TRUE);

View File

@ -67,7 +67,7 @@ return [
'providers' => [ 'providers' => [
'users' => [ 'users' => [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => App\User::class, 'model' => App\Models\User::class,
], ],
// 'users' => [ // 'users' => [

View File

@ -77,7 +77,7 @@ return [
| |
*/ */
'user' => 'App\User', 'user' => 'App\Models\User',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
<?php <?php
use App\User; use App\Models\User;
return [ return [

View File

@ -13,7 +13,7 @@ use Faker\Generator as Faker;
| |
*/ */
$factory->define(App\User::class, function (Faker $faker) { $factory->define(App\Models\User::class, function (Faker $faker) {
return [ return [
'name' => $faker->name, 'name' => $faker->name,
'email' => $faker->unique()->safeEmail, 'email' => $faker->unique()->safeEmail,

View File

@ -2,7 +2,7 @@
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use App\User; use App\Models\User;
class UserTableSeeder extends Seeder class UserTableSeeder extends Seeder
{ {