2020-05-18 19:54:43 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { yup } = require('strapi-utils');
|
|
|
|
|
2020-05-27 16:06:15 +02:00
|
|
|
const email = yup
|
|
|
|
.string()
|
|
|
|
.email()
|
|
|
|
.min(1);
|
|
|
|
|
|
|
|
const firstname = yup.string().min(1);
|
|
|
|
|
|
|
|
const lastname = yup.string().min(1);
|
2020-05-18 19:54:43 +02:00
|
|
|
|
2020-05-27 16:06:15 +02:00
|
|
|
const username = yup.string().min(1);
|
|
|
|
|
|
|
|
const password = yup
|
|
|
|
.string()
|
|
|
|
.min(8)
|
|
|
|
.matches(/[a-z]/, '${path} must contain at least one lowercase character')
|
|
|
|
.matches(/[A-Z]/, '${path} must contain at least one uppercase character')
|
|
|
|
.matches(/\d/, '${path} must contain at least one number');
|
|
|
|
|
2020-05-28 16:56:44 +02:00
|
|
|
const roles = yup.array(yup.strapiID()).min(1);
|
2020-05-27 16:06:15 +02:00
|
|
|
|
2020-06-09 17:45:53 +02:00
|
|
|
const isAPluginName = yup
|
|
|
|
.string()
|
|
|
|
.test('is-a-plugin-name', 'is not a plugin name', function(value) {
|
|
|
|
return [undefined, 'admin', ...Object.keys(strapi.plugins)].includes(value)
|
|
|
|
? true
|
|
|
|
: this.createError({ path: this.path, message: `${this.path} is not an existing plugin` });
|
|
|
|
});
|
|
|
|
|
2020-05-27 16:06:15 +02:00
|
|
|
module.exports = {
|
|
|
|
email,
|
|
|
|
firstname,
|
|
|
|
lastname,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
roles,
|
2020-06-09 17:45:53 +02:00
|
|
|
isAPluginName,
|
2020-05-27 16:06:15 +02:00
|
|
|
};
|