diff --git a/backend/app/Http/Controllers/AdminAuthController.php b/backend/app/Http/Controllers/AdminAuthController.php new file mode 100644 index 0000000..aa58424 --- /dev/null +++ b/backend/app/Http/Controllers/AdminAuthController.php @@ -0,0 +1,41 @@ +validate([ + 'email' => ['required','email'], + 'password' => ['required'], + ]); + + $remember = $request->boolean('remember'); + + if (Auth::guard('admin')->attempt($credentials, $remember)) { + $request->session()->regenerate(); + return redirect()->intended(route('admin.dashboard')); + } + + return back()->withErrors([ + 'email' => 'Email atau password salah.', + ])->onlyInput('email'); + } + + public function logout(Request $request) + { + Auth::guard('admin')->logout(); + $request->session()->invalidate(); + $request->session()->regenerateToken(); + return redirect()->route('admin.login'); + } +} diff --git a/backend/app/Http/Controllers/AdminAuthController.php.php b/backend/app/Http/Controllers/AdminAuthController.php.php deleted file mode 100644 index 62fab46..0000000 --- a/backend/app/Http/Controllers/AdminAuthController.php.php +++ /dev/null @@ -1,36 +0,0 @@ -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 index e8cd987..4678227 100644 --- a/backend/app/Models/Admin.php +++ b/backend/app/Models/Admin.php @@ -9,13 +9,7 @@ class Admin extends Authenticatable { use Notifiable; - protected $table = 'admins'; + protected $fillable = ['name','email','password']; - protected $fillable = [ - 'username', 'email', 'password', - ]; - - protected $hidden = [ - 'password', 'remember_token', - ]; + protected $hidden = ['password','remember_token']; } diff --git a/backend/config/auth.php b/backend/config/auth.php index 734d8e1..3a8d9d6 100644 --- a/backend/config/auth.php +++ b/backend/config/auth.php @@ -2,35 +2,11 @@ return [ - /* - |-------------------------------------------------------------------------- - | Authentication Defaults - |-------------------------------------------------------------------------- - | - | This option controls the default authentication "guard" and password - | reset options for your application. You may change these defaults - | as required, but they're a perfect start for most applications. - | - */ - 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], - /* - |-------------------------------------------------------------------------- - | Authentication Guards - |-------------------------------------------------------------------------- - | - | Next, you may define every authentication guard for your application. - | A great default configuration has been defined for you here which - | uses session storage and the Eloquent user provider. - | - | Supported drivers: "session", "token" - | - */ - 'guards' => [ // Guard untuk user biasa 'web' => [ @@ -38,39 +14,13 @@ return [ 'provider' => 'users', ], - // Guard untuk admin (login via web session) + // Guard untuk admin '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, - ], ], - /* - |-------------------------------------------------------------------------- - | User Providers - |-------------------------------------------------------------------------- - | - | All authentication drivers have a user provider. This defines how the - | users are retrieved from your database or other storage systems. - | - | Supported drivers: "database", "eloquent" - | - */ - 'providers' => [ // Provider untuk user biasa 'users' => [ @@ -83,25 +33,8 @@ return [ 'driver' => 'eloquent', 'model' => App\Models\Admin::class, ], - - // Kalau mau pakai database langsung (tidak lewat model) - // 'users' => [ - // 'driver' => 'database', - // 'table' => 'users', - // ], ], - /* - |-------------------------------------------------------------------------- - | Resetting Passwords - |-------------------------------------------------------------------------- - | - | 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. - | - */ - 'passwords' => [ 'users' => [ 'provider' => 'users', @@ -109,8 +42,6 @@ return [ 'expire' => 60, 'throttle' => 60, ], - - // Kalau admin juga butuh reset password, bisa tambahkan ini 'admins' => [ 'provider' => 'admins', 'table' => 'password_reset_tokens', @@ -119,16 +50,6 @@ return [ ], ], - /* - |-------------------------------------------------------------------------- - | Password Confirmation Timeout - |-------------------------------------------------------------------------- - | - | Jumlah detik sebelum konfirmasi password kadaluarsa. - | Default: 3 jam (10800 detik). - | - */ - 'password_timeout' => 10800, ]; 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 index b4e66a6..30675a0 100644 --- 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 @@ -5,10 +5,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up(): void { + public function up(): void + { Schema::create('admins', function (Blueprint $table) { $table->id(); - $table->string('username')->unique(); + $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); @@ -16,7 +17,8 @@ return new class extends Migration { }); } - public function down(): void { + public function down(): void + { Schema::dropIfExists('admins'); } }; diff --git a/backend/database/seeders/AdminSeeder.php b/backend/database/seeders/AdminSeeder.php index 077f5a0..54edbc5 100644 --- a/backend/database/seeders/AdminSeeder.php +++ b/backend/database/seeders/AdminSeeder.php @@ -2,16 +2,20 @@ namespace Database\Seeders; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; +use App\Models\Admin; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Hash; class AdminSeeder extends Seeder { - /** - * Run the database seeds. - */ public function run(): void { - // + Admin::updateOrCreate( + ['email' => 'admin@example.com'], + [ + 'name' => 'Super Admin', + 'password' => Hash::make('password123'), // ganti setelah login + ] + ); } } diff --git a/backend/database/seeders/DatabaseSeeder.php b/backend/database/seeders/DatabaseSeeder.php index a9f4519..126e57c 100644 --- a/backend/database/seeders/DatabaseSeeder.php +++ b/backend/database/seeders/DatabaseSeeder.php @@ -7,16 +7,10 @@ use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { - /** - * Seed the application's database. - */ public function run(): void - { - // \App\Models\User::factory(10)->create(); - - // \App\Models\User::factory()->create([ - // 'name' => 'Test User', - // 'email' => 'test@example.com', - // ]); - } +{ + $this->call([ + AdminSeeder::class, + ]); +} } diff --git a/backend/public/images/logo.png b/backend/public/images/logo.png new file mode 100644 index 0000000..2f25877 Binary files /dev/null and b/backend/public/images/logo.png differ diff --git a/backend/resources/views/admin/auth/login.blade.php b/backend/resources/views/admin/auth/login.blade.php new file mode 100644 index 0000000..4819afe --- /dev/null +++ b/backend/resources/views/admin/auth/login.blade.php @@ -0,0 +1,109 @@ + + + + + + + Login Admin + + + + + +
+
+ + +
+ +

SELAMAT DATANG

+

Selamat datang! Silakan masukkan detail Anda.

+ + @if ($errors->any()) +
+ {{ $errors->first() }} +
+ @endif + +
+ @csrf +
+ + +
+
+ + +
+
+
+ + +
+ Lupa kata sandi +
+ +
+
+ + + diff --git a/backend/resources/views/admin/dashboard.blade.php b/backend/resources/views/admin/dashboard.blade.php index 400aab4..f44277f 100644 --- a/backend/resources/views/admin/dashboard.blade.php +++ b/backend/resources/views/admin/dashboard.blade.php @@ -1,14 +1,21 @@ - - + + - Admin Dashboard + + + Admin Dashboard + - -

Halo, {{ Auth::guard('admin')->user()->username }}

- -
+ +
+
+

Admin Dashboard

+ @csrf - - + + +
+
Berhasil login sebagai {{ auth('admin')->user()->name }}
+
diff --git a/backend/resources/views/admin/login.blade.php b/backend/resources/views/admin/login.blade.php deleted file mode 100644 index ff86852..0000000 --- a/backend/resources/views/admin/login.blade.php +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - Login Admin - - - - - - - - -
- - Logo - -

WELCOME BACK

-

Welcome back! Please enter your details.

- - {{-- Notifikasi --}} - @if(session('error')) -
{{ session('error') }}
- @endif - @if(session('success')) -
{{ session('success') }}
- @endif - -
- @csrf -
- - -
-
- - -
- -
-
- - -
- Forgot password -
- - -
-
- - - diff --git a/backend/routes/web.php b/backend/routes/web.php index df440d2..85bea31 100644 --- a/backend/routes/web.php +++ b/backend/routes/web.php @@ -1,7 +1,19 @@ name('admin.login'); -Route::post('admin/login', [AdminAuthController::class, 'login'])->name('admin.login.post'); -Route::post('admin/logout', [AdminAuthController::class, 'logout'])->name('admin.logout'); +Route::prefix('admin')->name('admin.')->group(function () { + Route::middleware('guest:admin')->group(function () { + Route::get('/login', [AdminAuthController::class, 'showLogin'])->name('login'); + Route::post('/login', [AdminAuthController::class, 'login'])->name('login.post'); + }); + + Route::middleware('auth:admin')->group(function () { + Route::get('/dashboard', function () { + return view('admin.dashboard'); + })->name('dashboard'); + + Route::post('/logout', [AdminAuthController::class, 'logout'])->name('logout'); + }); +});