More changes to use form.select component. Re-engineered user BBS registration
This commit is contained in:
@@ -49,6 +49,9 @@ class SystemController extends Controller
|
||||
$o->autohold = FALSE;
|
||||
$o->save();
|
||||
|
||||
if ($o->wasRecentlyCreated)
|
||||
$o->users()->attach(Auth::id());
|
||||
|
||||
$mailers = collect($request->post('mailer_details'))
|
||||
->filter(function($item) { return $item['port']; })
|
||||
->transform(function($item) { $item['active'] = Arr::get($item,'active',FALSE); return $item; });
|
||||
@@ -621,39 +624,19 @@ class SystemController extends Controller
|
||||
*/
|
||||
public function register(SystemRegisterRequest $request)
|
||||
{
|
||||
if ($request->action === 'register' && $request->name && is_numeric($request->name))
|
||||
return view('user.system.widget.register_confirm')
|
||||
->with('o',System::findOrFail($request->name));
|
||||
// During the BBS linking process, if the user selected a system will link to confirm it
|
||||
if ($request->action === 'register' && $request->system_id && is_numeric($request->system_id))
|
||||
return redirect()
|
||||
->to(sprintf('user/system/register_confirm/%d',$request->system_id));
|
||||
|
||||
$o = System::findOrNew(is_numeric($request->system_id) ? $request->system_id : NULL);
|
||||
// Re-flash our previously input data, we must be creating a new system
|
||||
session()->flashInput([
|
||||
'name'=>$request->system_id,
|
||||
'sysop'=>Auth::user()->name,
|
||||
]);
|
||||
|
||||
// If the system doesnt exist, we'll create it
|
||||
if (! $o->exist) {
|
||||
$o->sysop = Auth::user()->name;
|
||||
|
||||
foreach (['name','zt_id','location','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 networks, 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('system/addedit',$o->id));
|
||||
}
|
||||
|
||||
// Re-flash our previously input data
|
||||
if ($request->old)
|
||||
session()->flashInput($request->old);
|
||||
|
||||
return view('system.widget.system')
|
||||
->with('action',$request->action)
|
||||
->with('o',$o)
|
||||
->with('errors',new ViewErrorBag);
|
||||
return redirect()
|
||||
->to('system/addedit');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -56,8 +56,11 @@ class SystemRegisterRequest extends FormRequest
|
||||
return [];
|
||||
|
||||
$so = $this->route('o');
|
||||
|
||||
// When we have selected a system during the register/linking process
|
||||
if ((! $so) && ($request->action === 'register'))
|
||||
return [];
|
||||
// If system ID is not numeric, then its a new system
|
||||
return is_numeric($request->system_id) ? ['system_id'=>'required|exists:systems,id'] : [];
|
||||
|
||||
return array_filter(array_merge([
|
||||
'name' => 'required|min:3',
|
||||
@@ -68,14 +71,16 @@ class SystemRegisterRequest extends FormRequest
|
||||
'port' => 'nullable|digits_between:2,5',
|
||||
'method' => 'nullable|numeric',
|
||||
'mailer_details.*' => 'nullable|array',
|
||||
// @todo Port should be present if active is true
|
||||
'mailer_details.*.port' => 'nullable|digits_between:2,5',
|
||||
'mailer_details.*.active' => 'sometimes|boolean',
|
||||
'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($so ? $so->id : 0),
|
||||
'pkt_type' => ['required',Rule::in(array_keys(Packet::PACKET_TYPES))],
|
||||
],($so && $so->exists) ? [
|
||||
'users' => 'nullable|array|min:1|max:2',
|
||||
'active' => 'required|boolean',
|
||||
'hold' => 'sometimes|boolean',
|
||||
'pollmode' => 'required|integer|min:0|max:2',
|
||||
],($so && $so->exists) ? [
|
||||
'users' => 'nullable|array|min:1|max:2',
|
||||
'heartbeat' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
|
@@ -25,6 +25,13 @@ class SystemPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function admin(User $user, System $system): bool
|
||||
{
|
||||
// Site Admins can always create
|
||||
// If it doesnt exist, then a user can create it.
|
||||
return ($user->isAdmin() || (! $system->exists));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create the model.
|
||||
*
|
||||
@@ -70,9 +77,9 @@ class SystemPolicy
|
||||
if ($user->isAdmin())
|
||||
return TRUE;
|
||||
|
||||
// If it doesnt exist, then its a false.
|
||||
// If it doesnt exist, then its a true (they are creating it).
|
||||
if (! $system->exists)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
|
||||
// @todo Permit ZC, RC, NC, HUB user
|
||||
|
||||
|
@@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
use App\Events\Echomail as EchomailEvent;
|
||||
@@ -18,7 +19,7 @@ use App\Helpers\PageAssets;
|
||||
use App\Listeners\EchomailListener;
|
||||
use App\Listeners\Matrix\MessageListener;
|
||||
use App\Notifications\Channels\{EchomailChannel,MatrixChannel,NetmailChannel};
|
||||
use App\Models\{Echomail,Netmail,User};
|
||||
use App\Models\{Echomail,Netmail,System,User};
|
||||
use App\Traits\Single;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -85,5 +86,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
// Custom Aliases
|
||||
$loader = AliasLoader::getInstance();
|
||||
$loader->alias('PageAssets',PageAssets::class);
|
||||
|
||||
Route::model('so',System::class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user