This commit is contained in:
Jesper 2024-10-09 19:54:18 +02:00
parent c9c88c5a22
commit f6b25a1a20
4 changed files with 8 additions and 10 deletions

View File

@ -20,12 +20,6 @@ const userController = new Elysia()
if(msg.administrator == 1) {return new Response(await user.createToken(msg.id), {status: 418})} if(msg.administrator == 1) {return new Response(await user.createToken(msg.id), {status: 418})}
return await user.createToken(msg.id) return await user.createToken(msg.id)
}) })
// .post('/register', async({body}) => {
// return await Bun.password.hash(body.password);
// })
.get('/otp', () => {
return authenticator.generateSecret();
})
.put('/password', ({user}, body) => { .put('/password', ({user}, body) => {
const oldPassword = body.oldPassword; const oldPassword = body.oldPassword;
const newPassword = body.newPassword; const newPassword = body.newPassword;
@ -38,7 +32,8 @@ const userController = new Elysia()
{return new Response("Bad old password", {status: 400})} {return new Response("Bad old password", {status: 400})}
} }
const newPasswordHash = Bun.password.hash(body.newPassword) const newPasswordHash = Bun.password.hash(body.newPassword)
const msg = db.query(`update users set password = ? WHERE id = ?;`).run(newPassword. user.id); db.query(`update users set password = ? WHERE id = ?;`).run(newPassword. user.id);
"password updated"
}) })
export default userController export default userController

View File

@ -9,6 +9,11 @@ const adminController = new Elysia()
.all(); .all();
return users return users
}) })
.get('/user/groups/:userID', ({params: {userID}}) => {
const userGroup = db.query(`SELECT groups.GroupId, groups.GroupName FROM groups JOIN userGroups ON groups.GroupID = userGroups.GroupID JOIN users ON userGroups.UserID = users.id WHERE users.id = ?;`)
.all(userID);
return userGroup
})
.post('/user/group/:groupId', ({params: {groupId}, body}) => { .post('/user/group/:groupId', ({params: {groupId}, body}) => {
db.query(`INSERT INTO userGroups (UserID, GroupID) VALUES (?, ?);`).run(groupId, body.userId); db.query(`INSERT INTO userGroups (UserID, GroupID) VALUES (?, ?);`).run(groupId, body.userId);
return "Added user to group" return "Added user to group"

View File

@ -29,9 +29,7 @@ const app = new Elysia()
name: msg.name, name: msg.name,
admin: msg.administrator admin: msg.administrator
} }
return { user } return { user }
// return user here instead of bearer
}) })
.get('/', ({ user }) => user) .get('/', ({ user }) => user)
.group('/user', (app) => app.use(userController)) .group('/user', (app) => app.use(userController))