User register system, minor cosmetic changes, start of user authorisation

This commit is contained in:
Deon George
2021-11-11 22:57:13 +11:00
parent a0db589dc5
commit 3c8895a238
15 changed files with 488 additions and 206 deletions

View File

@@ -3,8 +3,11 @@
namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ViewErrorBag;
use App\Models\{Address,Echoarea,System,SystemZone,Zone};
use App\Rules\{FidoInteger,TwoByteInteger};
@@ -284,6 +287,19 @@ class SystemController extends Controller
->with('o',$o);
}
/**
* Systems with no owners
*/
public function api_orphan(Request $request): Collection
{
return System::select(['id','name'])
->leftjoin('system_user',['system_user.system_id'=>'systems.id'])
->whereNull('user_id')
->where('systems.name','ilike','%'.$request->term.'%')
->orderBy('name')
->get();
}
/**
* Delete address assigned to a host
*
@@ -356,6 +372,11 @@ class SystemController extends Controller
->with('echoareas',$eo);
}
public function home()
{
return view('system.home');
}
/**
* Move address to another system
*
@@ -424,8 +445,33 @@ class SystemController extends Controller
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->system_id));
}
public function home()
/**
* register system
*/
public function system_register(Request $request)
{
return view('system.home');
$o = System::findOrNew($request->system_id);
if (! $o->exist) {
$o->sysop = Auth::user()->name;
foreach (['name','zt_id','location','mailer_type','mailer_address','mailer_port','phone','method','address','port'] as $item)
if ($request->{$item})
$o->{$item} = $request->{$item};
$o->active = TRUE;
}
if ($request->post('submit')) {
Auth::user()->systems()->save($o);
// @todo if the system already exists and part of one of our nextworks, we'll need to send the registration email to confirm the address.
// @todo mark the system (or addresses) as "pending" at this stage until it is confirmed
return redirect()->to(url('ftn/system/addedit',$o->id));
}
return view('system.widget.form-system')
->with('o',$o)
->with('errors',new ViewErrorBag);
}
}