1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/controllers/users/create.js

86 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
const Errors = {
2020-04-03 00:35:25 +05:00
EMAIL_ALREADY_IN_USE: {
emailAlreadyInUse: 'Email already in use',
},
USERNAME_ALREADY_IN_USE: {
usernameAlreadyInUse: 'Username already in use',
},
2019-08-31 04:07:25 +05:00
};
module.exports = {
inputs: {
email: {
type: 'string',
isEmail: true,
required: true,
2019-08-31 04:07:25 +05:00
},
password: {
type: 'string',
2022-08-26 18:59:44 +02:00
minLength: 6,
regex: /^(?=.*[A-Za-z])(?=.*\d).+$/,
required: true,
2019-08-31 04:07:25 +05:00
},
name: {
type: 'string',
required: true,
},
2020-04-03 00:35:25 +05:00
username: {
type: 'string',
isNotEmptyString: true,
minLength: 3,
maxLength: 16,
2021-04-13 18:59:02 +05:00
regex: /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/,
2020-04-03 00:35:25 +05:00
allowNull: true,
},
phone: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
organization: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
language: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
subscribeToOwnCards: {
type: 'boolean',
},
2019-08-31 04:07:25 +05:00
},
exits: {
2020-04-03 00:35:25 +05:00
emailAlreadyInUse: {
responseType: 'conflict',
},
usernameAlreadyInUse: {
responseType: 'conflict',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
const values = _.pick(inputs, [
'email',
'password',
'name',
'username',
'phone',
'organization',
'language',
'subscribeToOwnCards',
]);
2019-08-31 04:07:25 +05:00
const user = await sails.helpers.users
.createOne(values, this.req)
2020-04-03 00:35:25 +05:00
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
2019-08-31 04:07:25 +05:00
return {
item: user,
};
},
2019-08-31 04:07:25 +05:00
};