diff options
author | vantezzen <properly@protonmail.com> | 2019-08-26 10:31:24 +0200 |
---|---|---|
committer | vantezzen <properly@protonmail.com> | 2019-08-26 10:31:24 +0200 |
commit | ddedc080a28a46b7d9125682a3c990409908b70b (patch) | |
tree | ddbef921b6954a53984ea195dfbf24afcf367ae2 /app/Controllers/Http/ServiceController.js | |
parent | Add announcement route (diff) | |
download | ferdium-server-ddedc080a28a46b7d9125682a3c990409908b70b.tar.gz ferdium-server-ddedc080a28a46b7d9125682a3c990409908b70b.tar.zst ferdium-server-ddedc080a28a46b7d9125682a3c990409908b70b.zip |
Add validations
Diffstat (limited to 'app/Controllers/Http/ServiceController.js')
-rw-r--r-- | app/Controllers/Http/ServiceController.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/Controllers/Http/ServiceController.js b/app/Controllers/Http/ServiceController.js index d1adea3..0d1bae2 100644 --- a/app/Controllers/Http/ServiceController.js +++ b/app/Controllers/Http/ServiceController.js | |||
@@ -2,6 +2,10 @@ | |||
2 | 2 | ||
3 | const User = use('App/Models/User'); | 3 | const User = use('App/Models/User'); |
4 | const Service = use('App/Models/Service'); | 4 | const Service = use('App/Models/Service'); |
5 | const { | ||
6 | validateAll | ||
7 | } = use('Validator'); | ||
8 | |||
5 | const uuid = require('uuid/v4'); | 9 | const uuid = require('uuid/v4'); |
6 | 10 | ||
7 | class ServiceController { | 11 | class ServiceController { |
@@ -17,6 +21,18 @@ class ServiceController { | |||
17 | return response.send('Missing or invalid api token') | 21 | return response.send('Missing or invalid api token') |
18 | } | 22 | } |
19 | 23 | ||
24 | // Validate user input | ||
25 | const validation = await validateAll(request.all(), { | ||
26 | name: 'required|alpha', | ||
27 | recipeId: 'required', | ||
28 | }); | ||
29 | if (validation.fails()) { | ||
30 | return response.status(401).send({ | ||
31 | "message": "Invalid POST arguments", | ||
32 | "status": 401 | ||
33 | }) | ||
34 | } | ||
35 | |||
20 | const data = request.all(); | 36 | const data = request.all(); |
21 | 37 | ||
22 | // Get new, unused uuid | 38 | // Get new, unused uuid |
@@ -65,7 +81,6 @@ class ServiceController { | |||
65 | } catch (error) { | 81 | } catch (error) { |
66 | return response.send('Missing or invalid api token') | 82 | return response.send('Missing or invalid api token') |
67 | } | 83 | } |
68 | |||
69 | 84 | ||
70 | const services = (await auth.user.services().fetch()).rows; | 85 | const services = (await auth.user.services().fetch()).rows; |
71 | // Convert to array with all data Franz wants | 86 | // Convert to array with all data Franz wants |