diff --git a/app/api.js b/app/api.js index c6fa75e3..0f8c2fe2 100644 --- a/app/api.js +++ b/app/api.js @@ -2,44 +2,74 @@ const express = require('express') const { fillUser, isAuth, isAdmin } = require('./auth') const eventController = require('./controller/event') const exportController = require('./controller/export') +const userController = require('./controller/user') // const botController = require('./controller/bot') +const path = require('path') const multer = require('multer') -const upload = multer({ dest: 'uploads/' }) +const crypto = require('crypto') + +const storage = require('./storage')({ + destination: 'uploads/', + filename: (req, file, cb) => { + cb(null, crypto.randomBytes(16).toString('hex') + path.extname(file.originalname)) + } +}) +const upload = multer({ storage }) const api = express.Router() -// USER API -const userController = require('./controller/user') - +// login api.post('/login', userController.login) api.route('/user') + // register .post(userController.register) + // get current user .get(isAuth, userController.current) + // update user (eg. confirm) .put(isAuth, isAdmin, userController.update) +// get all users api.get('/users', isAuth, isAdmin, userController.getAll) + +// update a tag (modify color) api.put('/tag', isAuth, isAdmin, eventController.updateTag) + +// update a place (modify address..) api.put('/place', isAuth, isAdmin, eventController.updatePlace) api.route('/user/event') + // add event .post(fillUser, upload.single('image'), userController.addEvent) - .get(isAuth, userController.getMyEvents) + // update event .put(isAuth, upload.single('image'), userController.updateEvent) +// remove event api.delete('/user/event/:id', isAuth, userController.delEvent) +// get tags/places api.get('/event/meta', eventController.getMeta) -api.get('/event/unconfirmed', isAuth, isAdmin, eventController.getUnconfirmed) -api.post('/event/reminder', eventController.addReminder) +// get unconfirmed events +api.get('/event/unconfirmed', isAuth, isAdmin, eventController.getUnconfirmed) + +// add event reminder +api.post('/event/reminder', eventController.addReminder) +// api.del('/event/reminder/:id', eventController.delReminder) + +// get event api.get('/event/:event_id', eventController.get) + +// confirm event api.get('/event/confirm/:event_id', isAuth, isAdmin, eventController.confirm) +// export events (rss/ics) api.get('/export/:type', exportController.export) +// get events in this range api.get('/event/:year/:month', eventController.getAll) +// mastodon oauth auth api.post('/user/getauthurl', isAuth, userController.getAuthURL) api.post('/user/code', isAuth, userController.code) diff --git a/app/controller/user.js b/app/controller/user.js index 9c2d0008..7e5b7617 100644 --- a/app/controller/user.js +++ b/app/controller/user.js @@ -110,6 +110,9 @@ const userController = { async updateEvent (req, res) { const body = req.body const event = await Event.findByPk(body.id) + if (!req.user.is_admin && event.userId !== req.user.id) { + return res.sendStatus(403) + } body.description = body.description .replace(/(<([^>]+)>)/ig, '') // remove all tags from description @@ -142,11 +145,6 @@ const userController = { return res.json(newEvent) }, - async getMyEvents (req, res) { - const events = await req.user.getEvents() - res.json(events) - }, - async getAuthURL (req, res) { const instance = req.body.instance const { client_id, client_secret } = await Mastodon.createOAuthApp(`https://${instance}/api/v1/apps`, 'eventi', 'read write', `${config.baseurl}/settings`) diff --git a/app/db.js b/app/db.js index 926cfaf4..98f95a23 100644 --- a/app/db.js +++ b/app/db.js @@ -3,7 +3,7 @@ const conf = require('./config.js') console.error(conf.db) const db = new Sequelize(conf.db) -//db.sync({ force: true }) +// db.sync({ force: true }) // db.sync() module.exports = db diff --git a/client/babel.config.js b/client/babel.config.js index ba179669..e6616188 100644 --- a/client/babel.config.js +++ b/client/babel.config.js @@ -1,5 +1,14 @@ module.exports = { presets: [ - '@vue/app' + '@vue/app' //, 'es2015', { 'modules': false } + ], + plugins: [ + [ + 'component', + { + 'libraryName': 'element-ui', + 'styleLibraryName': 'theme-chalk' + } + ] ] } diff --git a/client/package.json b/client/package.json index 91fff9e9..14d0b35d 100644 --- a/client/package.json +++ b/client/package.json @@ -9,10 +9,11 @@ }, "dependencies": { "axios": "^0.18.0", + "babel-plugin-component": "^1.1.1", "bootstrap-vue": "^2.0.0-rc.13", + "dayjs": "^1.8.9", "element-ui": "^2.6.1", "mastodon-api": "^1.3.0", - "moment": "^2.23.0", "node-sass": "^4.11.0", "npm": "^6.8.0", "postcss-flexbugs-fixes": "^4.1.0", diff --git a/client/src/App.vue b/client/src/App.vue index e53ba9a2..1c03fe05 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -7,7 +7,7 @@