1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/helpers/create-user.js
2019-08-31 04:07:25 +05:00

46 lines
899 B
JavaScript

const bcrypt = require('bcrypt');
module.exports = {
inputs: {
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
_.isString(value.email) &&
_.isString(value.password),
required: true
},
request: {
type: 'ref'
}
},
exits: {
conflict: {}
},
fn: async function(inputs, exits) {
const user = await User.create({
...inputs.values,
email: inputs.values.email.toLowerCase(),
password: bcrypt.hashSync(inputs.values.password, 10)
})
.intercept(undefined, 'conflict')
.fetch();
const userIds = await sails.helpers.getAdminUserIds();
userIds.forEach(userId => {
sails.sockets.broadcast(
`user:${userId}`,
'userCreate',
{
item: user
},
inputs.request
);
});
return exits.success(user);
}
};