1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

Add username to user

This commit is contained in:
Maksim Eltyshev 2020-04-03 00:35:25 +05:00
parent 1320c697db
commit ce1e1f741d
143 changed files with 1051 additions and 420 deletions

View file

@ -4,8 +4,11 @@ module.exports = {
inputs: {
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) && _.isString(value.email) && _.isString(value.password),
custom: (value) =>
_.isPlainObject(value) &&
_.isString(value.email) &&
_.isString(value.password) &&
(!value.username || _.isString(value.username)),
required: true,
},
request: {
@ -14,10 +17,16 @@ module.exports = {
},
exits: {
conflict: {},
emailAlreadyInUse: {},
usernameAlreadyInUse: {},
},
async fn(inputs, exits) {
if (inputs.values.username) {
// eslint-disable-next-line no-param-reassign
inputs.values.username = inputs.values.username.toLowerCase();
}
const user = await User.create({
...inputs.values,
email: inputs.values.email.toLowerCase(),
@ -28,13 +37,20 @@ module.exports = {
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"',
},
'conflict',
'emailAlreadyInUse',
)
.intercept(
{
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_username_unique"',
},
'usernameAlreadyInUse',
)
.fetch();
const userIds = await sails.helpers.getAdminUserIds();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userCreate',