diff --git a/be/index.js b/be/index.js index b737952..474ee54 100644 --- a/be/index.js +++ b/be/index.js @@ -283,6 +283,79 @@ app.post('/login', (req, res) => { }); }); +// --- ADMIN PROFILE ENDPOINTS --- + +// Change Admin Password (Hardcoded logic) +let adminPassword = 'admin'; // In-memory variable. Resets to 'admin' if server restarts. + +app.put('/admin/change-password', (req, res) => { + const { current_password, new_password } = req.body; + if (current_password !== adminPassword) { + return res.status(401).json({ error: "Password saat ini salah!" }); + } + adminPassword = new_password; + res.json({ message: "Password Admin berhasil diubah!" }); +}); + +// GET Admin Image (Check if exists) +app.get('/admin/image', (req, res) => { + fs.readdir(imageDir, (err, files) => { + if (err) return res.status(500).json({ error: err.message }); + + // Find file starting with 'admin-profile-' + const adminFile = files.find(f => f.startsWith('admin-profile-')); + + if (adminFile) { + res.json({ has_image: true, image: adminFile }); + } else { + res.json({ has_image: false, image: null }); + } + }); +}); + +// Upload Admin Image (With Auto-Delete & Timestamp) +const uploadAdminImage = multer({ + storage: multer.diskStorage({ + destination: (req, file, cb) => cb(null, imageDir), + filename: (req, file, cb) => { + const ext = path.extname(file.originalname); + // Create unique name: admin-profile-timestamp.ext + cb(null, `admin-profile-${Date.now()}${ext}`); + } + }), + limits: { fileSize: 1024 * 1024 }, + fileFilter: (req, file, cb) => { + if (file.mimetype.startsWith('image/')) cb(null, true); + else cb(new Error('Hanya file gambar yang diizinkan!'), false); + } +}); + +app.put('/admin/upload-image', uploadAdminImage.single('image'), (req, res) => { + if (!req.file) return res.status(400).json({ error: "File gambar tidak ditemukan." }); + + const newFileName = req.file.filename; + + // Clean up old admin profile images + fs.readdir(imageDir, (err, files) => { + if (err) return res.status(500).json({ error: "Gagal membaca direktori gambar." }); + + // Loop through files to find old admin-profile-* and delete them + files.forEach(file => { + if (file.startsWith('admin-profile-') && file !== newFileName) { + const oldFilePath = path.join(imageDir, file); + fs.unlink(oldFilePath, (err) => { + if (err) console.error("Gagal menghapus gambar admin lama:", err); + else console.log("Gambar admin lama dihapus:", file); + }); + } + }); + + res.json({ message: "Foto profil Admin berhasil diperbarui!", image: newFileName }); + }); +}); + +// --- END ADMIN PROFILE ENDPOINTS --- + // ================= DOSEN ENDPOINTS ================= app.get('/dosen', (req, res) => { diff --git a/web/admin_index.html b/web/admin_index.html index 4fa16d9..2022489 100644 --- a/web/admin_index.html +++ b/web/admin_index.html @@ -25,6 +25,38 @@ body { display: none; } + + /* Image Preview Style */ + .profile-img-container { + text-align: center; + margin-bottom: 20px; + } + + .profile-img-preview { + width: 150px; + height: 150px; + object-fit: cover; + border-radius: 50%; + border: 4px solid #fff; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + margin-bottom: 15px; + } + + /* Fix for the top-left profile image to be a perfect circle */ + .header .avatar { + width: 65px; + height: 65px; + display: inline-block; + overflow: hidden; + border-radius: 50%; + vertical-align: middle; + } + + .header .avatar img { + width: 100%; + height: 100%; + object-fit: cover; + } @@ -34,7 +66,7 @@
-
Admin
Administrator
@@ -193,6 +225,19 @@ + if (localStorage.getItem('admin_auth') !== 'true') { + localStorage.clear(); + window.location.href = 'index.html'; + } + @@ -21,454 +22,541 @@ - - -
-
- -

Manajemen Dosen

-
-
-
- -
-
- -
-
- - -
-
-
-
- -

...

-

Jumlah Penelitian

-
-
+ - -
-
-
-
-

Daftar Dosen

-
- - - +
+
+ +

Manajemen Dosen

+
+
+
+ +
+
+ +
+
+ + +
+
+
+
+ +

...

+

Jumlah Penelitian

-
-
- - - - - - - - - - -
Dosen IDNama DosenJumlah PenelitianAksi
+
+
+
+
+ +

...

+

Penelitian Selesai

+
+
+
+
+
+
+ +

...

+

Jumlah Dosen

+
+
+
+
+
+
+ +

...

+

Update Terakhir

+
+ + +
+
+
+
+

Daftar Dosen

+
+ + + +
+
+
+
+ + + + + + + + + + +
Dosen IDNama DosenJumlah PenelitianAksi
+
+
+
+
+ +
+
    +
  • 2026 © Tugas RPL.
  • +
+
- -
-
    -
  • 2026 © Tugas RPL.
  • -
-
-
- -