mirror of
https://github.com/plankanban/planka.git
synced 2025-07-20 13:49:43 +02:00
Add username to user
This commit is contained in:
parent
ec222a5e32
commit
af00e3e191
143 changed files with 1051 additions and 420 deletions
|
@ -2,13 +2,13 @@ const bcrypt = require('bcrypt');
|
|||
|
||||
const Errors = {
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found',
|
||||
userNotFound: 'User not found',
|
||||
},
|
||||
CURRENT_PASSWORD_NOT_VALID: {
|
||||
forbidden: 'Current password is not valid',
|
||||
INVALID_CURRENT_PASSWORD: {
|
||||
invalidCurrentPassword: 'Invalid current password',
|
||||
},
|
||||
USER_EXIST: {
|
||||
conflict: 'User is already exist',
|
||||
EMAIL_ALREADY_IN_USE: {
|
||||
emailAlreadyInUse: 'Email already in use',
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -31,13 +31,13 @@ module.exports = {
|
|||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
userNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
forbidden: {
|
||||
invalidCurrentPassword: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
conflict: {
|
||||
emailAlreadyInUse: {
|
||||
responseType: 'conflict',
|
||||
},
|
||||
},
|
||||
|
@ -47,7 +47,7 @@ module.exports = {
|
|||
|
||||
if (inputs.id === currentUser.id) {
|
||||
if (!inputs.currentPassword) {
|
||||
throw Errors.CURRENT_PASSWORD_NOT_VALID;
|
||||
throw Errors.INVALID_CURRENT_PASSWORD;
|
||||
}
|
||||
} else if (!currentUser.isAdmin) {
|
||||
throw Errors.USER_NOT_FOUND; // Forbidden
|
||||
|
@ -63,14 +63,14 @@ module.exports = {
|
|||
inputs.id === currentUser.id &&
|
||||
!bcrypt.compareSync(inputs.currentPassword, user.password)
|
||||
) {
|
||||
throw Errors.CURRENT_PASSWORD_NOT_VALID;
|
||||
throw Errors.INVALID_CURRENT_PASSWORD;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['email']);
|
||||
|
||||
user = await sails.helpers
|
||||
.updateUser(user, values, this.req)
|
||||
.intercept('conflict', () => Errors.USER_EXIST);
|
||||
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue