mirror of
https://github.com/plankanban/planka.git
synced 2025-07-20 05:39:43 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
46
server/api/helpers/create-user.js
Normal file
46
server/api/helpers/create-user.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
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);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue