WIP: User table populated and login

This commit is contained in:
Deon George
2018-07-13 14:53:44 +10:00
parent 96673a9e53
commit 64b6c09b8f
22 changed files with 230 additions and 2692 deletions

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Account;
use App\User;
class UserAccountMerge extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:merge';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
foreach (Account::all() as $ao)
{
if (is_null($ao->user_id) AND $ao->email)
{
$o = User::where('email',$ao->email)->first();
if (! $o) {
$o = new User;
$o->id = $ao->id;
$o->site_id = $ao->site_id;
$o->email = $ao->email;
$o->password = $ao->password;
$o->active = $ao->active;
$o->title = $ao->title;
$o->firstname = $ao->first_name;
$o->lastname = $ao->last_name;
$o->country_id = $ao->country_id;
$o->address1 = $ao->address1;
$o->address2 = $ao->address2;
$o->city = $ao->city;
$o->state = $ao->state;
$o->postcode = $ao->zip;
$o->save();
}
$ao->user_id = $o->id;
$ao->save();
}
}
}
}

View File

@@ -2,6 +2,8 @@
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
class UserHomeController extends Controller
{
public function __construct()
@@ -11,6 +13,18 @@ class UserHomeController extends Controller
public function home()
{
return View('home');
switch (Auth::user()->role()) {
case 'Customer':
return View('home');
case 'Reseller':
break;
case 'Wholesaler':
break;
default:
abort(500,'Unknown role: ',Auth::user()->role());
}
}
}

View File

@@ -7,4 +7,23 @@ use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
protected $table = 'ab_account';
public $timestamps = FALSE;
/**
* Return the country the user belongs to
*/
public function country()
{
return $this->belongsTo(Country::class);
}
public function language()
{
return $this->belongsTo(Language::class);
}
public function user()
{
return $this->belongsTo(\App\User::class);
}
}

View File

@@ -29,7 +29,7 @@ class Invoice extends Model
public function account()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(Account::class);
}
public function items()

View File

@@ -23,7 +23,7 @@ class Payment extends Model
public function account()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(Account::class);
}
public function items()

View File

@@ -34,7 +34,7 @@ class Service extends Model
public function account()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(Account::class);
}
public function service_adsl()

View File

@@ -4,13 +4,14 @@ namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Cache;
use Laravel\Passport\HasApiTokens;
use Leenooks\Carbon;
use App\Models\Account;
use Leenooks\Traits\UserSwitch;
class User extends Authenticatable
{
use Notifiable;
use HasApiTokens,Notifiable,UserSwitch;
protected $dates = ['created_at','updated_at','last_access'];
@@ -32,12 +33,43 @@ class User extends Authenticatable
'password', 'remember_token',
];
public function accounts()
{
return $this->hasMany(Models\Account::class);
}
protected function agents() {
return $this->hasMany(static::class,'parent_id','id');
}
protected function clients() {
return $this->hasMany(\App\User::class);
}
public function invoices()
{
return $this->hasManyThrough(Models\Invoice::class,Models\Account::class);
}
public function payments()
{
return $this->hasManyThrough(Models\Payment::class,Models\Account::class);
}
public function services()
{
return $this->hasManyThrough(Models\Service::class,Models\Account::class);
}
protected function supplier()
{
return $this->belongsTo(static::class,'parent_id','id');
}
protected function suppliers() {
return $this->hasMany(static::class,'parent_id','id');
}
/**
* Logged in users full name
*
@@ -52,7 +84,7 @@ class User extends Authenticatable
* Return a Carbon Date if it has a value.
*
* @param $value
* @return Leenooks\Carbon
* @return \Leenooks\Carbon
* @todo This attribute is not in the schema
*/
public function getLastAccessAttribute($value)
@@ -60,6 +92,28 @@ class User extends Authenticatable
if (! is_null($value))
return new Carbon($value);
}
public function getInvoicesDueAttribute()
{
return $this->invoices
->where('active',TRUE)
->sortBy('id')
->transform(function ($item) { if ($item->due) return $item; })
->reverse()
->filter();
}
public function getPaymentHistoryAttribute()
{
return $this->payments
->sortBy('date_payment')
->reverse();
}
public function getServicesActiveAttribute()
{
return $this->services
->where('active',TRUE);
}
/**
* @deprecated Use static::getFullNameAttribute()
@@ -70,23 +124,6 @@ class User extends Authenticatable
return $this->full_name;
}
protected function agents() {
return $this->hasMany(static::class,'parent_id','id');
}
protected function clients() {
return $this->hasMany(\App\User::class);
}
protected function supplier()
{
return $this->belongsTo(static::class,'parent_id','id');
}
protected function suppliers() {
return $this->hasMany(static::class,'parent_id','id');
}
// List all the agents, including agents of agents
public function all_agents()
{