V1.0.0-beta.15 Update 2
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Note: We appreciate your feedback and bug reports to continue improving our platform. Thank you for your continued support!
This commit is contained in:
46
routes/Dpanel/API/ProfilPicture.js
Normal file
46
routes/Dpanel/API/ProfilPicture.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.use(express.json());
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const userId = req.body.userId;
|
||||||
|
const profilePictureUrl = req.body.profilePictureUrl;
|
||||||
|
|
||||||
|
if (!profilePictureUrl) {
|
||||||
|
return res.status(400).send('No profile picture URL provided.');
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUserProfilePicture(userId, profilePictureUrl, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateUserProfilePicture = (userId, profilePictureUrl, res) => {
|
||||||
|
const userFilePath = path.join(__dirname, '../../../data', 'user.json');
|
||||||
|
|
||||||
|
fs.readFile(userFilePath, 'utf8', (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).send('Error reading the file');
|
||||||
|
}
|
||||||
|
|
||||||
|
let users = JSON.parse(data);
|
||||||
|
|
||||||
|
const userIndex = users.findIndex(u => u.id === userId);
|
||||||
|
|
||||||
|
if (userIndex !== -1) {
|
||||||
|
users[userIndex].profilePicture = profilePictureUrl;
|
||||||
|
|
||||||
|
fs.writeFile(userFilePath, JSON.stringify(users, null, 2), err => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).send('Error writing to the file');
|
||||||
|
}
|
||||||
|
res.json({ profilePicture: profilePictureUrl });
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(404).send('User not found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
33
routes/Dpanel/Dashboard/ProfilUser.js
Normal file
33
routes/Dpanel/Dashboard/ProfilUser.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const router = express.Router();
|
||||||
|
const authMiddleware = require('../../../Middlewares/authMiddleware');
|
||||||
|
|
||||||
|
router.use(express.json());
|
||||||
|
|
||||||
|
router.get('/', authMiddleware, (req, res) => {
|
||||||
|
if (!req.user || !req.user.id) {
|
||||||
|
return res.status(401).send('Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
const userId = req.user.id;
|
||||||
|
|
||||||
|
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).send('Internal Server Error');
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = JSON.parse(data);
|
||||||
|
|
||||||
|
const user = users.find(u => u.id === userId);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).send('User not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
res.render('profile', { user });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
180
views/profile.ejs
Normal file
180
views/profile.ejs
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Profil Utilisateur</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-image: url('<%= user.wallpaper %>');
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-attachment: fixed;
|
||||||
|
margin: 0;
|
||||||
|
height: 100vh;
|
||||||
|
overflow: hidden;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
background: rgba(255, 255, 255, 0.8);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin: 10px 0 5px;
|
||||||
|
}
|
||||||
|
input[type="text"] {
|
||||||
|
width: calc(100% - 22px);
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
padding: 10px 20px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
.user-info {
|
||||||
|
margin: 20px 0;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.profile-picture {
|
||||||
|
margin: 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.profile-picture img {
|
||||||
|
max-width: 150px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.return-btn {
|
||||||
|
display: block;
|
||||||
|
margin: 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.badge {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="profile-picture">
|
||||||
|
<a class="btn dropdown-toggle" id="accountDropdownBtn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<img
|
||||||
|
src="<%= user.profilePicture || 'https://api.dicebear.com/7.x/initials/svg?seed=' + user.name %>"
|
||||||
|
alt="User Icon"
|
||||||
|
class="rounded-circle"
|
||||||
|
style="width: 30px; height: 30px;"
|
||||||
|
/>
|
||||||
|
</a> </div>
|
||||||
|
<h1>Bienvenue, <span id="userName"><%= user.name %></span> !</h1>
|
||||||
|
|
||||||
|
<div class="user-info">
|
||||||
|
<p><strong>ID :</strong> <span id="userId"><%= user.id %></span></p>
|
||||||
|
<p><strong>Rôle :</strong> <span id="userRole" class="badge"><%= user.role %></span></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="wallpaperForm">
|
||||||
|
<div>
|
||||||
|
<label for="wallpaperUrl">Entrez l'URL du fond d'écran :</label>
|
||||||
|
<input type="text" id="wallpaperUrl" name="wallpaperUrl" placeholder="http://example.com/image.jpg">
|
||||||
|
</div>
|
||||||
|
<button type="submit">Mettre à jour le fond d'écran</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form id="profilePictureForm">
|
||||||
|
<div>
|
||||||
|
<label for="profilePictureUrl">Entrez l'URL de la photo de profil :</label>
|
||||||
|
<input type="text" id="profilePictureUrl" name="profilePictureUrl" placeholder="http://example.com/path/to/profile.jpg">
|
||||||
|
</div>
|
||||||
|
<button type="submit">Mettre à jour la photo de profil</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="return-btn">
|
||||||
|
<button onclick="window.location.href='/dpanel/dashboard';">Retour au Dashboard</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const userId = '<%= user.id %>'; // Ensure this is set correctly by EJS
|
||||||
|
|
||||||
|
document.getElementById('wallpaperForm').addEventListener('submit', async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const urlInput = document.getElementById('wallpaperUrl').value;
|
||||||
|
|
||||||
|
if (urlInput) {
|
||||||
|
const response = await fetch('/api/dpanel/dashboard/backgroundcustom/wallpaper', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('token'),
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
wallpaperUrl: urlInput,
|
||||||
|
userId: userId // Ensure this is passed correctly
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
document.body.style.backgroundImage = `url('${data.wallpaper}')`;
|
||||||
|
alert('Fond d\'écran mis à jour avec succès !');
|
||||||
|
} else {
|
||||||
|
alert('Échec de la mise à jour du fond d\'écran');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('profilePictureForm').addEventListener('submit', async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const urlInput = document.getElementById('profilePictureUrl').value;
|
||||||
|
|
||||||
|
if (urlInput) {
|
||||||
|
const response = await fetch('/api/dpanel/dashboard/profilpicture', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('token'),
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
profilePictureUrl: urlInput,
|
||||||
|
userId: userId
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
document.getElementById('currentProfilePicture').src = data.profilePicture;
|
||||||
|
alert('Photo de profil mise à jour avec succès !');
|
||||||
|
} else {
|
||||||
|
alert('Échec de la mise à jour de la photo de profil');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user