2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
const { isPassword } = require('../../../utils/validators');
|
2022-09-03 22:47:06 +05:00
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
2024-02-01 00:31:15 +01:00
|
|
|
NOT_ENOUGH_RIGHTS: {
|
|
|
|
notEnoughRights: 'Not enough rights',
|
|
|
|
},
|
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-11-05 18:01:42 +05:00
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
ACTIVE_LIMIT_REACHED: {
|
|
|
|
activeLimitReached: 'Active limit reached',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
email: {
|
|
|
|
type: 'string',
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 256,
|
2019-08-31 04:07:25 +05:00
|
|
|
isEmail: true,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
password: {
|
|
|
|
type: 'string',
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 256,
|
|
|
|
custom: isPassword,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
role: {
|
|
|
|
type: 'string',
|
|
|
|
isIn: Object.values(User.Roles),
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 128,
|
2019-11-05 18:01:42 +05:00
|
|
|
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,
|
|
|
|
},
|
2020-04-09 18:27:28 +05:00
|
|
|
phone: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 128,
|
2020-04-09 18:27:28 +05:00
|
|
|
allowNull: true,
|
|
|
|
},
|
|
|
|
organization: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 128,
|
2020-04-09 18:27:28 +05:00
|
|
|
allowNull: true,
|
|
|
|
},
|
2022-07-26 12:26:42 +02:00
|
|
|
language: {
|
|
|
|
type: 'string',
|
2024-07-21 19:33:57 +02:00
|
|
|
isIn: User.LANGUAGES,
|
2022-07-26 12:26:42 +02:00
|
|
|
allowNull: true,
|
|
|
|
},
|
2020-04-10 00:11:34 +05:00
|
|
|
subscribeToOwnCards: {
|
|
|
|
type: 'boolean',
|
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
subscribeToCardWhenCommenting: {
|
|
|
|
type: 'boolean',
|
|
|
|
},
|
|
|
|
turnOffRecentCardHighlighting: {
|
|
|
|
type: 'boolean',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
2024-02-01 00:31:15 +01:00
|
|
|
notEnoughRights: {
|
|
|
|
responseType: 'forbidden',
|
|
|
|
},
|
2020-04-03 00:35:25 +05:00
|
|
|
emailAlreadyInUse: {
|
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
|
|
|
usernameAlreadyInUse: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
activeLimitReached: {
|
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2024-06-12 00:51:36 +02:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
2024-02-01 00:31:15 +01:00
|
|
|
if (sails.config.custom.oidcEnforced) {
|
|
|
|
throw Errors.NOT_ENOUGH_RIGHTS;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:27:28 +05:00
|
|
|
const values = _.pick(inputs, [
|
|
|
|
'email',
|
|
|
|
'password',
|
2025-05-10 02:09:06 +02:00
|
|
|
'role',
|
2020-04-09 18:27:28 +05:00
|
|
|
'name',
|
|
|
|
'username',
|
|
|
|
'phone',
|
|
|
|
'organization',
|
2022-07-26 12:26:42 +02:00
|
|
|
'language',
|
2020-04-10 00:11:34 +05:00
|
|
|
'subscribeToOwnCards',
|
2025-05-10 02:09:06 +02:00
|
|
|
'subscribeToCardWhenCommenting',
|
|
|
|
'turnOffRecentCardHighlighting',
|
2020-04-09 18:27:28 +05:00
|
|
|
]);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
const user = await sails.helpers.users.createOne
|
|
|
|
.with({
|
|
|
|
values,
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: currentUser,
|
2022-12-26 21:10:50 +01:00
|
|
|
request: this.req,
|
|
|
|
})
|
2020-04-03 00:35:25 +05:00
|
|
|
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
|
2025-05-10 02:09:06 +02:00
|
|
|
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE)
|
|
|
|
.intercept('activeLimitReached', () => Errors.ACTIVE_LIMIT_REACHED);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
2025-05-10 02:09:06 +02:00
|
|
|
item: sails.helpers.users.presentOne(user, currentUser),
|
2021-06-24 01:05:22 +05:00
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|