diff --git a/backend/app/Http/Controllers/AdminAuthController.php.php b/backend/app/Http/Controllers/AdminAuthController.php.php new file mode 100644 index 0000000..62fab46 --- /dev/null +++ b/backend/app/Http/Controllers/AdminAuthController.php.php @@ -0,0 +1,36 @@ +only('email', 'password'); + + if (Auth::guard('admin')->attempt($credentials)) { + return redirect()->route('admin.dashboard')->with('success', 'Login berhasil!'); + } + + return back()->with('error', 'Email atau password salah.'); + } + + // Logout + public function logout(Request $request) + { + Auth::guard('admin')->logout(); + return redirect()->route('admin.login'); + } +} diff --git a/backend/app/Models/Admin.php b/backend/app/Models/Admin.php new file mode 100644 index 0000000..e8cd987 --- /dev/null +++ b/backend/app/Models/Admin.php @@ -0,0 +1,21 @@ + [ + // Guard untuk user biasa 'web' => [ 'driver' => 'session', 'provider' => 'users', ], + + // Guard untuk admin (login via web session) + 'admin' => [ + 'driver' => 'session', + 'provider' => 'admins', + ], + + // Guard API untuk user (misalnya dengan sanctum / token) + 'api' => [ + 'driver' => 'token', + 'provider' => 'users', + 'hash' => false, + ], + + // Guard API untuk admin + 'admin-api' => [ + 'driver' => 'token', + 'provider' => 'admins', + 'hash' => false, + ], ], /* @@ -48,23 +65,26 @@ return [ |-------------------------------------------------------------------------- | | All authentication drivers have a user provider. This defines how the - | users are actually retrieved out of your database or other storage - | mechanisms used by this application to persist your user's data. + | users are retrieved from your database or other storage systems. | - | If you have multiple user tables or models you may configure multiple - | sources which represent each model / table. These sources may then - | be assigned to any extra authentication guards you have defined. - | - | Supported: "database", "eloquent" + | Supported drivers: "database", "eloquent" | */ 'providers' => [ + // Provider untuk user biasa 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], + // Provider untuk admin + 'admins' => [ + 'driver' => 'eloquent', + 'model' => App\Models\Admin::class, + ], + + // Kalau mau pakai database langsung (tidak lewat model) // 'users' => [ // 'driver' => 'database', // 'table' => 'users', @@ -76,17 +96,9 @@ return [ | Resetting Passwords |-------------------------------------------------------------------------- | - | You may specify multiple password reset configurations if you have more - | than one user table or model in the application and you want to have - | separate password reset settings based on the specific user types. - | - | The expire time is the number of minutes that each reset token will be - | considered valid. This security feature keeps tokens short-lived so - | they have less time to be guessed. You may change this as needed. - | - | The throttle setting is the number of seconds a user must wait before - | generating more password reset tokens. This prevents the user from - | quickly generating a very large amount of password reset tokens. + | Anda dapat menentukan beberapa konfigurasi reset password jika ada + | lebih dari satu tabel atau model user dan ingin pengaturan reset + | yang berbeda berdasarkan tipe user tertentu. | */ @@ -97,6 +109,14 @@ return [ 'expire' => 60, 'throttle' => 60, ], + + // Kalau admin juga butuh reset password, bisa tambahkan ini + 'admins' => [ + 'provider' => 'admins', + 'table' => 'password_reset_tokens', + 'expire' => 60, + 'throttle' => 60, + ], ], /* @@ -104,9 +124,8 @@ return [ | Password Confirmation Timeout |-------------------------------------------------------------------------- | - | Here you may define the amount of seconds before a password confirmation - | times out and the user is prompted to re-enter their password via the - | confirmation screen. By default, the timeout lasts for three hours. + | Jumlah detik sebelum konfirmasi password kadaluarsa. + | Default: 3 jam (10800 detik). | */ diff --git a/backend/database/migrations/2025_08_29_091312_create_admins_table.php.php b/backend/database/migrations/2025_08_29_091312_create_admins_table.php.php new file mode 100644 index 0000000..b4e66a6 --- /dev/null +++ b/backend/database/migrations/2025_08_29_091312_create_admins_table.php.php @@ -0,0 +1,22 @@ +id(); + $table->string('username')->unique(); + $table->string('email')->unique(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + } + + public function down(): void { + Schema::dropIfExists('admins'); + } +}; diff --git a/backend/resources/views/admin/dashboard.blade.php b/backend/resources/views/admin/dashboard.blade.php new file mode 100644 index 0000000..400aab4 --- /dev/null +++ b/backend/resources/views/admin/dashboard.blade.php @@ -0,0 +1,14 @@ + + +
+Welcome back! Please enter your details.
+ + {{-- Notifikasi --}} + @if(session('error')) +