user checking when user uploads
This commit is contained in:
		
							parent
							
								
									795f983721
								
							
						
					
					
						commit
						ef58af8a9a
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		|  | @ -3,14 +3,18 @@ import * as fs from 'fs'; | ||||||
| const StreamZip = require('node-stream-zip'); | const StreamZip = require('node-stream-zip'); | ||||||
| 
 | 
 | ||||||
| import { parseSM } from './lib/smparse'; | import { parseSM } from './lib/smparse'; | ||||||
| import { File } from './schema'; | import { File, User } from './schema'; | ||||||
| 
 | 
 | ||||||
| export function run(app) { | export function run(app) { | ||||||
| 	const logger = app.get('logger'); | 	const logger = app.get('logger'); | ||||||
| 	 | 	 | ||||||
| 	app.post('/api/upload', async (req, res) => { // only for testing, very abusable
 | 	app.post('/api/upload', async (req, res) => { // only for testing, very abusable
 | ||||||
| 		if (!req.files) return res.status(400).send('No files were given'); | 		if (!req.files) return res.status(400).send('No files were given'); | ||||||
| 		if (!req.session.uuid) return res.status(401).send('Not authorized'); | 		if (!req.session.uuid) return res.status(401).send('Not authorized, use /discordauth'); | ||||||
|  | 
 | ||||||
|  | 		const user = (await User.find({uuid: req.session.uuid}))[0]; | ||||||
|  | 		if (!user) return res.status(401).send('User doesn\'t exist, try re-logging in'); | ||||||
|  | 		if (!user.get('approvedUpload')) return res.status(403).send('Your account is not allowed to upload files! Contact a moderator to verify your account'); | ||||||
| 		 | 		 | ||||||
| 		const file = req.files.file; | 		const file = req.files.file; | ||||||
| 	 | 	 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue