diff --git a/back/api/auth.js b/back/api/auth.js index ccec218..0ee7828 100644 --- a/back/api/auth.js +++ b/back/api/auth.js @@ -44,7 +44,7 @@ router.post('/me', async (req, res) => { const users = await getUser(connection, decoded.id); connection.end(); if (users[0]) { - res.send({ id: users[0].id, username: users[0].username }); + res.send({ id: users[0].id, username: users[0].username, admin: users[0].admin }); } else { res.status(401).send({ error: 'Invalid token' }); } diff --git a/back/api/channels.js b/back/api/channels.js index e1060db..388052d 100644 --- a/back/api/channels.js +++ b/back/api/channels.js @@ -77,7 +77,7 @@ router.post('/:name/messages/delete', async (req, res) => { return res.status(400).send({ error: 'No channel found' }); } - if (user[0].id !== channel[0].owner_id && user[0].id !== message_id) { + if (user[0].id !== channel[0].owner_id && user[0].id !== message_id && user[0].admin !== 1) { connection.end(); return res.status(401).send({ error: 'Unauthorized' }); } diff --git a/back/api/users.js b/back/api/users.js index 9b7b065..4fb42c4 100644 --- a/back/api/users.js +++ b/back/api/users.js @@ -10,7 +10,7 @@ router.get('/:id', async (req, res) => { const users = await getUser(connection, id); connection.end(); if (users[0]) { - res.send({id: users[0].id, username: users[0].username}); + res.send({id: users[0].id, username: users[0].username, admin: users[0].admin}); } else { res.send('No user found'); } diff --git a/back/libs/mysql.js b/back/libs/mysql.js index 25c1d88..d07eb21 100644 --- a/back/libs/mysql.js +++ b/back/libs/mysql.js @@ -68,7 +68,7 @@ function getChannels(connection) { function getChannel(connection, name) { return new Promise((resolve, reject) => { connection.query( - `SELECT * FROM channels WHERE name = "${name}"`, + `SELECT channels.id, name, description, owner_id, username AS owner_username FROM channels JOIN users ON channels.owner_id = users.id WHERE name = "${name}"`, (error, result) => { if (error) { reject(new Error(error)); diff --git a/front/public/cat.jpg b/front/public/cat.jpg new file mode 100644 index 0000000..5dbe289 Binary files /dev/null and b/front/public/cat.jpg differ diff --git a/front/src/index.css b/front/src/index.css index e69de29..329fece 100644 --- a/front/src/index.css +++ b/front/src/index.css @@ -0,0 +1,3 @@ +.cat { + width: 100px; +} \ No newline at end of file diff --git a/front/src/pages/Channel.tsx b/front/src/pages/Channel.tsx index 7956b20..7799e0b 100644 --- a/front/src/pages/Channel.tsx +++ b/front/src/pages/Channel.tsx @@ -73,6 +73,10 @@ export default function Channel() { Home
{channel.description}
+Owner: {channel.owner_username}
+ {channel.name.toLowerCase().includes("cat") && ( +