generated from lucien/api-template
add: improved frontend and added descriptions to users
This commit is contained in:
parent
6342377aa0
commit
eca9efc170
14 changed files with 266 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
|||
const express = require('express');
|
||||
const sha256 = require("sha256");
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { getConnection, getUserByUsername, addUser, setUserPfp, setUserUsername, setUserPassword } = require('../libs/mysql');
|
||||
const { getConnection, getUserByUsername, addUser, setUserPfp, setUserUsername, setUserPassword, setUserDescription } = require('../libs/mysql');
|
||||
const { checkAuth } = require('../libs/middlewares');
|
||||
const multer = require('multer')
|
||||
const rateLimit = require("express-rate-limit");
|
||||
|
@ -82,7 +82,7 @@ router.post('/register', speedLimiter, limiter, async (req, res) => {
|
|||
|
||||
router.post('/me', checkAuth, async (req, res) => {
|
||||
const user = req.user;
|
||||
res.send({ id: user.id, username: user.username, admin: user.admin });
|
||||
res.send({ id: user.id, username: user.username, admin: user.admin , description: user.description });
|
||||
});
|
||||
|
||||
router.post('/me/uploadpfp', upload.single('pfp'), checkAuth, async (req, res) => {
|
||||
|
@ -151,4 +151,18 @@ router.post('/me/setpassword', checkAuth, async (req, res) => {
|
|||
res.send({ message: 'Password changed.' });
|
||||
});
|
||||
|
||||
router.post('/me/setdescription', checkAuth, async (req, res) => {
|
||||
const { description } = req.body;
|
||||
const user = req.user;
|
||||
|
||||
if (!description) {
|
||||
return res.status(400).send({ error: 'Invalid description' });
|
||||
}
|
||||
|
||||
const connection = await getConnection();
|
||||
await setUserDescription(connection, user.id, description);
|
||||
connection.end();
|
||||
res.send({ message: 'Description changed.' });
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -37,7 +37,7 @@ router.get('/:username', async (req, res) => {
|
|||
const user = await getUserByUsername(connection, username);
|
||||
connection.end();
|
||||
if (user[0]) {
|
||||
res.send({id: user[0].id, username: user[0].username, admin: user[0].admin});
|
||||
res.send({id: user[0].id, username: user[0].username, admin: user[0].admin, description: user[0].description});
|
||||
} else {
|
||||
return res.status(400).send({ error: 'No user found' });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue