Archived
2

switched device_name to devices

This commit is contained in:
VLE2FE
2020-08-06 13:58:12 +02:00
parent 18e0809a99
commit cc6fa48a44
20 changed files with 1318 additions and 1269 deletions

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
export default class IdValidate {
private static id = Joi.string().pattern(new RegExp('[0-9a-f]{24}')).length(24).messages({'string.pattern.base': 'Invalid object id'});

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import IdValidate from './id';

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import IdValidate from './id';

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
export default class NoteFieldValidate {
private static note_field = {

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
export default class ParametersValidate {
static input (data, parameters, param) { // data to validate, parameters from template, param: 'new', 'change', 'null'(null values are allowed)

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import IdValidate from './id';
export default class RootValidate { // validate input for root methods

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import IdValidate from './id';
import UserValidate from './user';

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import IdValidate from './id';
// TODO: do not allow a . in the name !!!

View File

@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import globals from '../../globals';
import IdValidate from './id';
@ -28,12 +28,14 @@ export default class UserValidate { // validate input for user
.alphanum()
.max(128),
device_name: Joi.string()
.allow('')
.max(128),
devices: Joi.array()
.items(Joi.string()
.allow('')
.max(128)
)
};
private static specialUsernames = ['admin', 'user', 'key', 'new', 'passreset']; // names a user cannot take
private static specialUsernames: string[] = ['admin', 'user', 'key', 'new', 'passreset']; // names a user cannot take
static input (data, param) { // validate input, set param to 'new' to make all attributes required
if (param === 'new') {
@ -43,7 +45,7 @@ export default class UserValidate { // validate input for user
pass: this.user.pass.required(),
level: this.user.level.required(),
location: this.user.location.required(),
device_name: this.user.device_name.required()
devices: this.user.devices.required()
}).validate(data);
}
else if (param === 'change') {
@ -52,7 +54,7 @@ export default class UserValidate { // validate input for user
email: this.user.email,
pass: this.user.pass,
location: this.user.location,
device_name: this.user.device_name
devices: this.user.devices
}).validate(data);
}
else if (param === 'changeadmin') {
@ -62,7 +64,7 @@ export default class UserValidate { // validate input for user
pass: this.user.pass,
level: this.user.level,
location: this.user.location,
device_name: this.user.device_name
devices: this.user.devices
}).validate(data);
}
else {
@ -78,8 +80,9 @@ export default class UserValidate { // validate input for user
email: this.user.email,
level: this.user.level,
location: this.user.location,
device_name: this.user.device_name
devices: this.user.devices
}).validate(data, {stripUnknown: true});
console.log(data);
return error !== undefined? null : value;
}