Started work on SiteDetails and Setup
This commit is contained in:
60
app/Http/Controllers/AdminHomeController.php
Normal file
60
app/Http/Controllers/AdminHomeController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\SiteDetails;
|
||||
|
||||
class AdminHomeController extends Controller
|
||||
{
|
||||
public function setup()
|
||||
{
|
||||
return view('a.setup');
|
||||
}
|
||||
|
||||
public function setup_update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'site_name' => 'required|string|max:255',
|
||||
'site_email' => 'required|string|email|max:255',
|
||||
'site_address1' => 'required|string|max:255',
|
||||
'site_address2' => 'nullable|string|max:255',
|
||||
'site_city' => 'required|string|max:64',
|
||||
'site_state' => 'required|string|max:32',
|
||||
'site_postcode' => 'required|string|max:8',
|
||||
'site_phone' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
|
||||
'site_fax' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
|
||||
]);
|
||||
|
||||
// If we are more input that sample data, reject the update.
|
||||
if (config('SITE_SETUP')->allowed_keys(array_keys($request->except('_token'))))
|
||||
return redirect()->back()
|
||||
->withInput()
|
||||
->withErrors('Invalid configuration - values not expected.');
|
||||
|
||||
foreach ($request->except('_token') as $key => $value)
|
||||
{
|
||||
if (! $value) {
|
||||
SiteDetails::where('site_id',config('SITE_SETUP')->id)->where('key',$key)->delete();
|
||||
|
||||
} else {
|
||||
try {
|
||||
|
||||
// Update or create our config record.
|
||||
SiteDetails::updateOrCreate([
|
||||
'site_id'=>config('SITE_SETUP')->id,
|
||||
'key'=>$key,
|
||||
],[
|
||||
'value'=>$value,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
dd($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Setup Updated!');;
|
||||
}
|
||||
}
|
@@ -14,17 +14,17 @@ class UserHomeController extends Controller
|
||||
public function home()
|
||||
{
|
||||
switch (Auth::user()->role()) {
|
||||
case 'Customer':
|
||||
case 'customer':
|
||||
return View('userhome',['o'=>Auth::user()]);
|
||||
|
||||
case 'Reseller':
|
||||
case 'reseller':
|
||||
return View('resellerhome',['o'=>Auth::user()]);
|
||||
|
||||
case 'Wholesaler':
|
||||
case 'wholesaler':
|
||||
return View('resellerhome',['o'=>Auth::user()]);
|
||||
|
||||
default:
|
||||
abort(500,'Unknown role: ',Auth::user()->role());
|
||||
abort(500,'Unknown role: '.Auth::user()->role());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,10 +6,6 @@ use Auth;
|
||||
|
||||
class UserServicesController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return ['data'=>Auth::user()->invoices_due->values()];
|
||||
|
@@ -61,7 +61,7 @@ class Kernel extends HttpKernel
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'demoMode' => \Spatie\DemoMode\DemoMode::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'reseller' => \App\Http\Middleware\Reseller::class,
|
||||
'role' => \App\Http\Middleware\Role::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'theme' => \Igaster\LaravelTheme\Middleware\setTheme::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
|
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Closure;
|
||||
|
||||
class Reseller
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (! in_array(Auth::user()->role(),['Wholesaler','Reseller']))
|
||||
{
|
||||
abort(303,'Not Reseller');
|
||||
|
||||
} else
|
||||
return $next($request);
|
||||
}
|
||||
}
|
31
app/Http/Middleware/Role.php
Normal file
31
app/Http/Middleware/Role.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Closure;
|
||||
|
||||
class Role
|
||||
{
|
||||
public function handle($request, Closure $next, $role)
|
||||
{
|
||||
if ($role AND ! Auth::user())
|
||||
return abort(303,'Not Authenticated');
|
||||
|
||||
switch ($role) {
|
||||
case 'wholesaler':
|
||||
if (Auth::user()->role() == $role)
|
||||
return $next($request);
|
||||
|
||||
break;
|
||||
|
||||
case 'reseller':
|
||||
if (in_array(Auth::user()->role(),['wholesaler','reseller']))
|
||||
return $next($request);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
abort(404,'User doesnt have role?');
|
||||
}
|
||||
}
|
@@ -29,11 +29,9 @@ class SetSite
|
||||
// @todo Figure out how to know if this is an API call - and deny it if it's not in the database.
|
||||
$so = new Site;
|
||||
|
||||
if (Schema::hasTable('site'))
|
||||
if ($so->getTable() AND Schema::hasTable($so->getTable()))
|
||||
{
|
||||
$so = Site::where('url',$request->root())
|
||||
->orwhere('devurl',$request->root())
|
||||
// @todo With an API call, we would use ->firstorfail();
|
||||
->first();
|
||||
}
|
||||
|
||||
|
@@ -3,16 +3,64 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Site extends Model
|
||||
{
|
||||
protected $table = 'ab_setup';
|
||||
public $timestamps = FALSE;
|
||||
|
||||
protected $with = ['details'];
|
||||
|
||||
protected $casts = [
|
||||
'address'=>'array',
|
||||
];
|
||||
|
||||
public function details()
|
||||
{
|
||||
return $this->hasMany(SiteDetails::class);
|
||||
}
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
// @todo Not sure if this is functioning correctly?
|
||||
if ($parent = parent::__get($key))
|
||||
return $parent;
|
||||
|
||||
// Deprecated Items
|
||||
if (! in_array($key,array_keys($this->_sampledata())))
|
||||
{
|
||||
Log::alert('No sample data for Key:',['key'=>$key]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$detail = $this->details->where('key',$key)->first();
|
||||
|
||||
if ($detail) {
|
||||
return $detail->value;
|
||||
}
|
||||
|
||||
// Suppress some default values
|
||||
$optional = [
|
||||
'block_quotes',
|
||||
'clients',
|
||||
'page_tabs',
|
||||
'services',
|
||||
'site_description',
|
||||
'site_fax',
|
||||
'site_address2',
|
||||
'site_slider',
|
||||
'steps',
|
||||
'testimonials',
|
||||
];
|
||||
|
||||
if (in_array($key,$optional))
|
||||
return '';
|
||||
|
||||
Log::alert('Calling unknown Site Key:',['key'=>$key]);
|
||||
return array_get($this->_sampledata(),$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-load this model with Sample Data, if there is no database record
|
||||
*/
|
||||
@@ -72,7 +120,26 @@ class Site extends Model
|
||||
],
|
||||
],
|
||||
'clients_intro'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore',
|
||||
'main_slider'=>[
|
||||
'page_tabs'=>[
|
||||
[
|
||||
'title'=>'Title 1',
|
||||
'image'=>'/image/generic/200/100/999',
|
||||
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
|
||||
|
||||
],
|
||||
[
|
||||
'title'=>'Title 2',
|
||||
'image'=>'/image/generic/200/100/799',
|
||||
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
|
||||
|
||||
],
|
||||
[
|
||||
'title'=>'Title 3',
|
||||
'image'=>'/image/generic/200/100/979',
|
||||
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
|
||||
],
|
||||
],
|
||||
'site_slider'=>[
|
||||
[
|
||||
'title'=>'Header <br/><span class="carousel-title-normal">and Title</span>',
|
||||
'text'=>'This is what you were looking for',
|
||||
@@ -97,40 +164,21 @@ class Site extends Model
|
||||
//'button'=>['text'=>'Purchase Now','url'=>'#'],
|
||||
],
|
||||
],
|
||||
'page_tabs'=>[
|
||||
[
|
||||
'title'=>'Title 1',
|
||||
'image'=>'/image/generic/200/100/999',
|
||||
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
|
||||
|
||||
],
|
||||
[
|
||||
'title'=>'Title 2',
|
||||
'image'=>'/image/generic/200/100/799',
|
||||
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
|
||||
|
||||
],
|
||||
[
|
||||
'title'=>'Title 3',
|
||||
'image'=>'/image/generic/200/100/979',
|
||||
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
|
||||
],
|
||||
],
|
||||
'site'=>[
|
||||
'id'=>NULL,
|
||||
'address'=>json_decode('{"address1":"PO Box 149","address2":"7 Woodlands Court","city":"Bendigo","state":"VIC","postcode":"3550"}'),
|
||||
'address1'=>'Building Name',
|
||||
'address2'=>'123 Road Street',
|
||||
'city'=>'City',
|
||||
'description'=>'Example Site',
|
||||
'email'=>'nobody@example.com',
|
||||
'fax'=>'+0 1 2345 6789',
|
||||
'logo'=>route('image',['width'=>128,'height'=>32,'color'=>'eee']),
|
||||
'name'=>'Example',
|
||||
'postalcode'=>'123 456',
|
||||
'phone'=>'+0 1 2345 6789',
|
||||
'state'=>'State',
|
||||
],
|
||||
'site_address1'=>'Building Name',
|
||||
'site_address2'=>NULL,
|
||||
'site_city'=>'City',
|
||||
'site_description'=>'Example Site',
|
||||
'site_email'=>'nobody@example.com',
|
||||
'site_fax'=>'+0 1 2345 6789',
|
||||
'site_name'=>'Example',
|
||||
'site_phone'=>'+0 1 2345 6789',
|
||||
'site_postcode'=>'123 456',
|
||||
'site_state'=>'State',
|
||||
'site_tax'=>'12 123 123 123',
|
||||
'services'=>[
|
||||
['title'=>'Title 1','text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','icon'=>'fa fa-location-arrow blue','image'=>NULL],
|
||||
['title'=>'Title 2','text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','icon'=>'fa fa-compress green','image'=>NULL],
|
||||
@@ -182,66 +230,6 @@ class Site extends Model
|
||||
];
|
||||
}
|
||||
|
||||
public function getActivitiesAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'activity');
|
||||
}
|
||||
|
||||
public function getActivityIntroAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'activity_intro');
|
||||
}
|
||||
|
||||
public function getClientsAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'clients');
|
||||
}
|
||||
|
||||
public function getCLientsIntoAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'clients_info');
|
||||
}
|
||||
|
||||
public function getServicesAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'services');
|
||||
}
|
||||
|
||||
public function getBlockQuotesAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'block_quotes');
|
||||
}
|
||||
|
||||
public function getPageTabsAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'page_tabs');
|
||||
}
|
||||
|
||||
public function getSiteSliderAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'main_slider');
|
||||
}
|
||||
|
||||
public function getSocialAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'social');
|
||||
}
|
||||
|
||||
public function getStepsAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'steps');
|
||||
}
|
||||
|
||||
public function getTestimonialsAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'testimonials');
|
||||
}
|
||||
|
||||
public function getTopMenuAttribute()
|
||||
{
|
||||
return array_get($this->_sampledata(),'top_menu');
|
||||
}
|
||||
|
||||
public function sample()
|
||||
{
|
||||
return $this->forceFill(array_get($this->_sampledata(),'site'));
|
||||
@@ -257,12 +245,12 @@ class Site extends Model
|
||||
{
|
||||
$return = [];
|
||||
|
||||
if ($this->address1)
|
||||
array_push($return,$this->address1);
|
||||
if ($this->address2)
|
||||
array_push($return,$this->address2);
|
||||
if ($this->city)
|
||||
array_push($return,sprintf('%s %s %s',$this->city.(($this->state OR $this->postalcode) ? ',' : ''),$this->state,$this->postalcode));
|
||||
if ($this->site_address1)
|
||||
array_push($return,$this->site_address1);
|
||||
if ($this->site_address2)
|
||||
array_push($return,$this->site_address2);
|
||||
if ($this->site_city)
|
||||
array_push($return,sprintf('%s %s %s',$this->site_city.(($this->site_state OR $this->site_postcode) ? ',' : ''),$this->site_state,$this->site_postcode));
|
||||
|
||||
if (! $return)
|
||||
$return = ['No Address'];
|
||||
@@ -270,6 +258,11 @@ class Site extends Model
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function allowed_keys(array $keys=[])
|
||||
{
|
||||
return $keys ? array_diff($keys,array_keys($this->_sampledata())) : array_keys($this->_sampledata());
|
||||
}
|
||||
|
||||
public function address($type='plain')
|
||||
{
|
||||
switch ($type)
|
||||
@@ -282,10 +275,6 @@ class Site extends Model
|
||||
}
|
||||
}
|
||||
|
||||
public function fax()
|
||||
{
|
||||
return '@todo';
|
||||
}
|
||||
public function logo_url()
|
||||
{
|
||||
return url($this->logo ? $this->logo : '/image/generic/150/20/fff');
|
||||
|
22
app/Models/SiteDetails.php
Normal file
22
app/Models/SiteDetails.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Leenooks\Traits\CompositeKeys;
|
||||
|
||||
class SiteDetails extends Model
|
||||
{
|
||||
use CompositeKeys;
|
||||
|
||||
public $fillable = ['site_id','key','value'];
|
||||
public $incrementing = false;
|
||||
protected $primaryKey = ['site_id','key'];
|
||||
public $timestamps = FALSE;
|
||||
|
||||
public function site()
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
}
|
@@ -213,14 +213,14 @@ class User extends Authenticatable
|
||||
{
|
||||
// If I have agents and no parent, I am the wholesaler
|
||||
if (is_null($this->parent_id) AND $this->all_agents()->count())
|
||||
return 'Wholesaler';
|
||||
return 'wholesaler';
|
||||
|
||||
// If I have agents and a parent, I am a reseller
|
||||
elseif ($this->parent_id AND $this->all_agents()->count())
|
||||
return 'Reseller';
|
||||
return 'reseller';
|
||||
|
||||
// If I have no agents and a parent, I am a customer
|
||||
elseif (! $this->all_agents()->count())
|
||||
return 'Customer';
|
||||
return 'customer';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user