From e45f366b7653086515805631473e2cdcf6ccd294 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 19 Jun 2021 01:09:34 +1000 Subject: [PATCH] User editing and creation by system admin --- app/Http/Controllers/UserController.php | 19 ++- .../2021_06_18_133000_update_users.php | 42 +++++++ resources/views/auth/login.blade.php | 14 +-- .../views/auth/passwords/email.blade.php | 12 +- .../views/auth/passwords/reset.blade.php | 28 ++--- resources/views/auth/register.blade.php | 40 +++---- resources/views/domain/addedit.blade.php | 14 +-- .../views/layouts/partials/sidebar.blade.php | 2 +- resources/views/system/addedit.blade.php | 50 ++++---- resources/views/user/addedit.blade.php | 111 ++++++++++++++++++ resources/views/zone/addedit.blade.php | 38 +++--- routes/web.php | 2 + 12 files changed, 256 insertions(+), 116 deletions(-) create mode 100644 database/migrations/2021_06_18_133000_update_users.php create mode 100644 resources/views/user/addedit.blade.php diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index d306dec..524be45 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use Illuminate\Auth\Events\Registered; use Illuminate\Http\Request; use App\Models\User; @@ -22,14 +23,28 @@ class UserController extends Controller $this->authorize('admin',$o); $request->validate([ - 'email' => 'required|email|unique:users,email,'.($o ? $o->id : NULL), + 'email' => 'required|email|unique:users,email,'.($o->exists ? $o->id : 0), + 'name' => 'required|min:3', + 'pgp_pubkey' => [ + 'nullable', + 'min:64', + //function ($attribute,$value,$fail) { return $fail('Not this time'); } + ], + 'active' => 'required|boolean', + 'admin' => 'required|boolean', ]); - foreach (['name','email','notes'] as $key) + foreach (['name','email','pgp_pubkey','active','admin'] as $key) $o->{$key} = $request->post($key); + if (! $o->exists) + $o->password = base64_encode(random_bytes(20)); + $o->save(); + if ($o->wasRecentlyCreated) + event(new Registered($o)); + return redirect()->action([self::class,'home']); } diff --git a/database/migrations/2021_06_18_133000_update_users.php b/database/migrations/2021_06_18_133000_update_users.php new file mode 100644 index 0000000..98db015 --- /dev/null +++ b/database/migrations/2021_06_18_133000_update_users.php @@ -0,0 +1,42 @@ +text('pgp_pubkey')->nullable(); + $table->boolean('active')->default(TRUE); + $table->dateTime('last_on')->nullable(); + }); + + Schema::table('systems', function (Blueprint $table) { + $table->dateTime('last_session')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn(['pgp_pubkey','active','last_on']); + }); + + Schema::table('systems', function (Blueprint $table) { + $table->dropColumn(['last_session']); + }); + } +} diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 52f221c..77351db 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -34,15 +34,13 @@
- @error('email') - + + @error('email') {{ $message }} - - @else - + @else Your email is required. - - @enderror + @enderror +
@@ -53,7 +51,7 @@
- + Your password is required.
diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index b3cbfbd..f0d60ca 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -29,15 +29,13 @@
- @error('email') - + + @error('email') {{ $message }} - - @else - + @else Your email is required. - - @enderror + @enderror +
diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index eaffe8c..ab5b7c3 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -30,15 +30,13 @@
- @error('email') - + + @error('email') {{ $message }} - - @else - + @else Your email is required. - - @enderror + @enderror +
@@ -49,15 +47,13 @@
- @error('password') - + + @error('password') {{ $message }} - - @else - + @else Your password is required. - - @enderror + @enderror +
@@ -68,9 +64,9 @@
-
+ Please re-enter your password. -
+
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index d977657..53d09b9 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -19,15 +19,13 @@
- @error('name') - + + @error('name') {{ $message }} - - @else - + @else Your name is required. - - @enderror + @enderror +
@@ -38,15 +36,13 @@
- @error('email') - + + @error('email') {{ $message }} - - @else - + @else Your email is required. - - @enderror + @enderror +
@@ -57,15 +53,13 @@
- @error('password') - + + @error('password') {{ $message }} - - @else -
+ @else Your password is required. -
- @enderror + @enderror +
@@ -76,9 +70,9 @@
-
+ Please re-enter your password. -
+
diff --git a/resources/views/domain/addedit.blade.php b/resources/views/domain/addedit.blade.php index 25f793f..231618f 100644 --- a/resources/views/domain/addedit.blade.php +++ b/resources/views/domain/addedit.blade.php @@ -19,15 +19,13 @@
- @error('name') - + + @error('name') {{ $message }} - - @else - + @else A name is required. - - @enderror + @enderror +
@@ -89,7 +87,7 @@

Home Page

-
+
diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index 8349a43..1abe345 100644 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -12,7 +12,7 @@ @can('admin')
Users
-
Create
+
Create
List
@endcan diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 6ad3ad6..4eec86a 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -19,15 +19,13 @@
- @error('name') - + + @error('name') {{ $message }} - - @else - + @else A name is required. - - @enderror + @enderror +
@@ -51,15 +49,13 @@
- @error('sysop') - + + @error('sysop') {{ $message }} - - @else - + @else A Sysop's name is required. - - @enderror + @enderror +
@@ -68,15 +64,13 @@
- @error('location') - + + @error('location') {{ $message }} - - @else - + @else System location is required. - - @enderror + @enderror +
@@ -103,16 +97,14 @@ - @error('address') - + + @error('address') {{ $message }} - - @enderror - @error('port') - + @enderror + @error('port') {{ $message }} - - @enderror + @enderror + diff --git a/resources/views/user/addedit.blade.php b/resources/views/user/addedit.blade.php new file mode 100644 index 0000000..5d8738d --- /dev/null +++ b/resources/views/user/addedit.blade.php @@ -0,0 +1,111 @@ +@extends('layouts.app') + +@section('htmlheader_title') + @if($o->exists) Update @else Add @endif User +@endsection + +@section('content') +
+ @csrf + +
+
+
+

@if($o->exists) Update @else Add @endif User

+ +
+
+ +
+ + + + @error('name') + {{ $message }} + @else + A name is required. + @enderror + +
+
+ +
+ +
+
+ active))checked @endif> + + + active))checked @endif> + +
+
+
+
+ +
+
+ +
+ + + + @error('email') + {{ $message }} + @else + Email required for login. + @enderror + +
+
+ +
+ +
+
id == Auth::user()->id)data-bs-toggle="tooltip" title="You cannot demote yourself" @endif> + admin))checked @endif> + + + id == Auth::user()->id || Auth::user()->cannot('admin',$o)) disabled @endif @if(! old('admin',$o->admin))checked @endif> + +
+
+
+
+ +
+
+ + + + @error('pgp_pubkey') + {{ $message }} + @enderror + +
+
+ +
+
+ Cancel + @can('admin',$o) + + @endcan +
+
+
+
+
+
+@endsection + +@section('page-scripts') + @if($o->id == Auth::user()->id) + + @endif +@append \ No newline at end of file diff --git a/resources/views/zone/addedit.blade.php b/resources/views/zone/addedit.blade.php index eab7f80..c54c817 100644 --- a/resources/views/zone/addedit.blade.php +++ b/resources/views/zone/addedit.blade.php @@ -19,15 +19,13 @@
- @error('zone_id') - + + @error('zone_id') {{ $message }} - - @else - + @else A zone number is required. - - @enderror + @enderror +
@@ -41,15 +39,13 @@ @endforeach - @error('domain_id') - + + @error('domain_id') {{ $message }} - - @else - + @else A domain is required. - - @enderror + @enderror + Add a NEW Domain @@ -64,22 +60,20 @@ @endforeach - @error('system_id') - + + @error('system_id') {{ $message }} - - @else - + @else A system is required. - - @enderror + @enderror + Add a NEW System. This system is the primary mailer/tosser responsible for managing the zone.
-
+
active))checked @endif> diff --git a/routes/web.php b/routes/web.php index 5f9b6d9..bd3dba4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -55,4 +55,6 @@ Route::middleware(['auth','can:admin'])->group(function () { Route::get('setup',[HomeController::class,'setup']); Route::get('user/list',[UserController::class,'home']); + Route::match(['get','post'],'user/addedit/{o?}',[UserController::class,'add_edit']) + ->where('o','[0-9]+'); }); \ No newline at end of file