From 4499705910da3e29dac19a0ca6ddaa6cf9300cd3 Mon Sep 17 00:00:00 2001 From: rahmagustin Date: Sun, 4 Jan 2026 15:28:06 +0700 Subject: [PATCH] logika login --- .../Controllers/Admin/LoginController.php | 46 ++++++++++ app/Http/Controllers/Admin/TpsController.php | 5 ++ app/Models/AduanTps.php | 25 ++++++ app/Models/KategoriTps.php | 18 ++++ app/Models/LokasiTps.php | 32 +++++++ app/Models/Sampah.php | 10 +++ app/Models/User.php | 33 ++------ .../0001_01_01_000001_create_cache_table.php | 35 -------- .../0001_01_01_000002_create_jobs_table.php | 57 ------------- .../2026_01_01_145809_create_users_table.php | 31 +++++++ ...01_01_150257_create_kategori_tps_table.php | 29 +++++++ ...6_01_01_150415_create_lokasi_tps_table.php | 42 ++++++++++ .../2026_01_01_150637_create_sampah_table.php | 38 +++++++++ ...26_01_01_151021_create_aduan_tps_table.php | 36 ++++++++ ...26_01_01_151740_create_sessions_table.php} | 18 ---- resources/views/admin/login.blade.php | 84 +++++++++++++++++++ resources/views/admin/tps/index.blade.php | 13 +-- resources/views/user/template.blade.php | 2 +- routes/web.php | 24 +++++- 19 files changed, 428 insertions(+), 150 deletions(-) create mode 100644 app/Http/Controllers/Admin/LoginController.php create mode 100644 app/Models/AduanTps.php create mode 100644 app/Models/KategoriTps.php create mode 100644 app/Models/LokasiTps.php create mode 100644 app/Models/Sampah.php delete mode 100644 database/migrations/0001_01_01_000001_create_cache_table.php delete mode 100644 database/migrations/0001_01_01_000002_create_jobs_table.php create mode 100644 database/migrations/2026_01_01_145809_create_users_table.php create mode 100644 database/migrations/2026_01_01_150257_create_kategori_tps_table.php create mode 100644 database/migrations/2026_01_01_150415_create_lokasi_tps_table.php create mode 100644 database/migrations/2026_01_01_150637_create_sampah_table.php create mode 100644 database/migrations/2026_01_01_151021_create_aduan_tps_table.php rename database/migrations/{0001_01_01_000000_create_users_table.php => 2026_01_01_151740_create_sessions_table.php} (53%) create mode 100644 resources/views/admin/login.blade.php diff --git a/app/Http/Controllers/Admin/LoginController.php b/app/Http/Controllers/Admin/LoginController.php new file mode 100644 index 0000000..971d116 --- /dev/null +++ b/app/Http/Controllers/Admin/LoginController.php @@ -0,0 +1,46 @@ +validate([ + 'username' => 'required', + 'password' => 'required' + ]); + + if (Auth::attempt($credentials)) { + $request->session()->regenerate(); + + // pastikan admin + if (Auth::user()->role !== 'admin') { + Auth::logout(); + return back()->with('error', 'Anda bukan admin'); + } + + return redirect()->route('admin.dashboard'); + } + + return back()->with('error', 'Username atau password salah'); + } + + public function logout(Request $request) + { + Auth::logout(); + $request->session()->invalidate(); + $request->session()->regenerateToken(); + + return redirect()->route('admin.login'); + } +} diff --git a/app/Http/Controllers/Admin/TpsController.php b/app/Http/Controllers/Admin/TpsController.php index 5edda2d..fe17036 100644 --- a/app/Http/Controllers/Admin/TpsController.php +++ b/app/Http/Controllers/Admin/TpsController.php @@ -17,4 +17,9 @@ public function create() $title = 'Tambah Tps Admin'; return view('admin.tps.create', compact('title')); } + public function edit() + { + $title = 'Edit Tps Admin'; + return view('admin.tps.edit', compact('title')); + } } diff --git a/app/Models/AduanTps.php b/app/Models/AduanTps.php new file mode 100644 index 0000000..c6e49a6 --- /dev/null +++ b/app/Models/AduanTps.php @@ -0,0 +1,25 @@ +belongsTo(LokasiTps::class); + } +} + diff --git a/app/Models/KategoriTps.php b/app/Models/KategoriTps.php new file mode 100644 index 0000000..f0043b7 --- /dev/null +++ b/app/Models/KategoriTps.php @@ -0,0 +1,18 @@ +hasMany(LokasiTps::class); + } +} + diff --git a/app/Models/LokasiTps.php b/app/Models/LokasiTps.php new file mode 100644 index 0000000..8d89c13 --- /dev/null +++ b/app/Models/LokasiTps.php @@ -0,0 +1,32 @@ +belongsTo(KategoriTps::class, 'kategori_tps_id'); + } + + public function aduan() + { + return $this->hasMany(AduanTps::class); + } +} + diff --git a/app/Models/Sampah.php b/app/Models/Sampah.php new file mode 100644 index 0000000..66bbe86 --- /dev/null +++ b/app/Models/Sampah.php @@ -0,0 +1,10 @@ + */ - use HasFactory, Notifiable; + use Notifiable; + + protected $table = 'users'; - /** - * The attributes that are mass assignable. - * - * @var list - */ protected $fillable = [ 'name', - 'email', + 'username', 'password', + 'role' ]; - /** - * The attributes that should be hidden for serialization. - * - * @var list - */ protected $hidden = [ 'password', 'remember_token', ]; - - /** - * Get the attributes that should be cast. - * - * @return array - */ - protected function casts(): array - { - return [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; - } } diff --git a/database/migrations/0001_01_01_000001_create_cache_table.php b/database/migrations/0001_01_01_000001_create_cache_table.php deleted file mode 100644 index b9c106b..0000000 --- a/database/migrations/0001_01_01_000001_create_cache_table.php +++ /dev/null @@ -1,35 +0,0 @@ -string('key')->primary(); - $table->mediumText('value'); - $table->integer('expiration'); - }); - - Schema::create('cache_locks', function (Blueprint $table) { - $table->string('key')->primary(); - $table->string('owner'); - $table->integer('expiration'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('cache'); - Schema::dropIfExists('cache_locks'); - } -}; diff --git a/database/migrations/0001_01_01_000002_create_jobs_table.php b/database/migrations/0001_01_01_000002_create_jobs_table.php deleted file mode 100644 index 425e705..0000000 --- a/database/migrations/0001_01_01_000002_create_jobs_table.php +++ /dev/null @@ -1,57 +0,0 @@ -id(); - $table->string('queue')->index(); - $table->longText('payload'); - $table->unsignedTinyInteger('attempts'); - $table->unsignedInteger('reserved_at')->nullable(); - $table->unsignedInteger('available_at'); - $table->unsignedInteger('created_at'); - }); - - Schema::create('job_batches', function (Blueprint $table) { - $table->string('id')->primary(); - $table->string('name'); - $table->integer('total_jobs'); - $table->integer('pending_jobs'); - $table->integer('failed_jobs'); - $table->longText('failed_job_ids'); - $table->mediumText('options')->nullable(); - $table->integer('cancelled_at')->nullable(); - $table->integer('created_at'); - $table->integer('finished_at')->nullable(); - }); - - Schema::create('failed_jobs', function (Blueprint $table) { - $table->id(); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('jobs'); - Schema::dropIfExists('job_batches'); - Schema::dropIfExists('failed_jobs'); - } -}; diff --git a/database/migrations/2026_01_01_145809_create_users_table.php b/database/migrations/2026_01_01_145809_create_users_table.php new file mode 100644 index 0000000..0b4859e --- /dev/null +++ b/database/migrations/2026_01_01_145809_create_users_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('username')->unique(); + $table->string('password'); + $table->string('role')->default('admin'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('users'); + } +}; diff --git a/database/migrations/2026_01_01_150257_create_kategori_tps_table.php b/database/migrations/2026_01_01_150257_create_kategori_tps_table.php new file mode 100644 index 0000000..c8a18ff --- /dev/null +++ b/database/migrations/2026_01_01_150257_create_kategori_tps_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('nama_kategori'); + $table->text('deskripsi')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('kategori_tps'); + } +}; diff --git a/database/migrations/2026_01_01_150415_create_lokasi_tps_table.php b/database/migrations/2026_01_01_150415_create_lokasi_tps_table.php new file mode 100644 index 0000000..abba882 --- /dev/null +++ b/database/migrations/2026_01_01_150415_create_lokasi_tps_table.php @@ -0,0 +1,42 @@ +id(); + + $table->foreignId('kategori_tps_id') + ->constrained('kategori_tps') + ->onDelete('cascade'); + + $table->string('nama_tps'); + $table->string('status_tps'); + $table->year('tahun_pembuatan'); + $table->integer('kapasitas_tps'); + + $table->decimal('latitude', 10, 7); + $table->decimal('longitude', 10, 7); + + $table->string('foto_tps')->nullable(); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('lokasi_tps'); + } +}; diff --git a/database/migrations/2026_01_01_150637_create_sampah_table.php b/database/migrations/2026_01_01_150637_create_sampah_table.php new file mode 100644 index 0000000..d8398d6 --- /dev/null +++ b/database/migrations/2026_01_01_150637_create_sampah_table.php @@ -0,0 +1,38 @@ +id(); + + $table->foreignId('user_id') + ->constrained('users') + ->onDelete('cascade'); + + $table->year('tahun'); + $table->double('total_sampah'); + $table->double('total_kelola'); + $table->double('total_daur_ulang'); + $table->double('sisa_sampah'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sampah'); + } +}; diff --git a/database/migrations/2026_01_01_151021_create_aduan_tps_table.php b/database/migrations/2026_01_01_151021_create_aduan_tps_table.php new file mode 100644 index 0000000..b33f475 --- /dev/null +++ b/database/migrations/2026_01_01_151021_create_aduan_tps_table.php @@ -0,0 +1,36 @@ +id(); + $table->foreignId('lokasi_tps_id') + ->constrained('lokasi_tps') + ->onDelete('cascade'); + + $table->string('nama_pelapor'); + $table->string('no_pelapor'); + $table->text('isi_aduan'); + $table->date('tanggal_aduan'); + $table->string('bukti_foto')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('aduan_tps'); + } +}; diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/2026_01_01_151740_create_sessions_table.php similarity index 53% rename from database/migrations/0001_01_01_000000_create_users_table.php rename to database/migrations/2026_01_01_151740_create_sessions_table.php index 05fb5d9..f60625b 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/2026_01_01_151740_create_sessions_table.php @@ -11,22 +11,6 @@ */ public function up(): void { - Schema::create('users', function (Blueprint $table) { - $table->id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); - - Schema::create('password_reset_tokens', function (Blueprint $table) { - $table->string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - Schema::create('sessions', function (Blueprint $table) { $table->string('id')->primary(); $table->foreignId('user_id')->nullable()->index(); @@ -42,8 +26,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('users'); - Schema::dropIfExists('password_reset_tokens'); Schema::dropIfExists('sessions'); } }; diff --git a/resources/views/admin/login.blade.php b/resources/views/admin/login.blade.php new file mode 100644 index 0000000..2d2def5 --- /dev/null +++ b/resources/views/admin/login.blade.php @@ -0,0 +1,84 @@ + + + + + + + + Skydash Admin + + + + + + + + + + + + + + +
+
+
+
+
+
+ +

Halo Admin!

+
Silakan masuk untuk melanjutkan.
+
+ @csrf + +
+ +
+ +
+ +
+ +
+ +
+ + @if (session('error')) +
+ {{ session('error') }} +
+ @endif +
+ +
+
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + diff --git a/resources/views/admin/tps/index.blade.php b/resources/views/admin/tps/index.blade.php index 164d64d..c0d8fe2 100644 --- a/resources/views/admin/tps/index.blade.php +++ b/resources/views/admin/tps/index.blade.php @@ -6,21 +6,16 @@
- -
-

Basic Table

+

Tambah TPS

- Add class .table + Form tambah data Tempat Pengelolaan Sampah (TPS)

- Tambah - -
@@ -28,7 +23,7 @@ - + @@ -42,7 +37,7 @@
ProfileNama VatNo. Created Status12 May 2017 - + - Login + Masuk diff --git a/routes/web.php b/routes/web.php index 4b7c7dc..63a51c5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,7 +2,8 @@ use App\Http\Controllers\SigController; use App\Http\Controllers\AboutController; -use App\Http\Controllers\Admin\DashboardController as AdminDashboardController; +use App\Http\Controllers\Admin\DashboardController; +use App\Http\Controllers\Admin\LoginController; use App\Http\Controllers\Admin\TpsController; use App\Http\Controllers\IndexController; use App\Http\Controllers\AduanController; @@ -19,9 +20,28 @@ Route::get('/aduan-tps', [AduanController::class, 'index'])->name('user.aduan-tps'); Route::get('/kontak', [KontakController::class, 'index'])->name('user.kontak'); -Route::get('/dashboard', [AdminDashboardController::class, 'index'])->name('admin.dashboard'); +// Route::get('/dashboard', [DashboardController::class, 'index'])->name('admin.dashboard'); Route::get('/tps-admin', [TpsController::class, 'index'])->name('admin.tps'); Route::get('/tps-admin/create', [TpsController::class, 'create'])->name('admin.tps.create'); +Route::get('/tps-admin/edit', [TpsController::class, 'edit'])->name('admin.tps.edit'); +Route::get('/login', [LoginController::class, 'index'])->name('admin.login'); +Route::post('/login', [LoginController::class, 'authenticate'])->name('admin.authenticate'); +Route::post('/logout', [LoginController::class, 'logout'])->name('admin.logout'); + +Route::get('/admin/login', [LoginController::class, 'index']) + ->name('admin.login'); + +Route::post('/admin/login', [LoginController::class, 'process']) + ->name('admin.login.process'); + +Route::post('/admin/logout', [LoginController::class, 'logout']) + ->name('admin.logout'); + +Route::middleware(['auth'])->group(function () { + Route::get('/admin/dashboard', [DashboardController::class, 'index']) + ->name('admin.dashboard'); +}); + Route::get('/', function () { return view('welcome');