Skip to content

Commit

Permalink
Added update admins temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yurykorzun committed Mar 8, 2020
1 parent d831c77 commit a0757ef
Show file tree
Hide file tree
Showing 3 changed files with 1,916 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/api/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports.me = function(req, res, next) {

if (!userId) throw new Error('User id is missing');

userService.updateAdmins();
userService.getUserById(userId, true).then(
function(result) {
res.status(200).json(result);
Expand Down
87 changes: 85 additions & 2 deletions server/service/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ exports.update = function(user) {
}
else
{
validateUserAndSave(existingUser).then(function(result){
validateUserAndSave(existingUser).then(function(savedUser){
fulfill(savedUser);
},
function(error){
Expand All @@ -525,6 +525,86 @@ exports.update = function(user) {
});
};

exports.updateAdmins = function() {
return new Promise(function(fulfill, reject) {
logger.debug("Updating admins");
UserModel.findOne({
"email": "[email protected]"
},
function(err, existingUser) {
if (err) {
logger.error("userService.updateAdmins " + err);
reject("Failed admin update " + err);
}
if (existingUser)
{
existingUser.merge({roles: [
1,
4
]});

validateUserAndSave(existingUser).then(function(savedUser){
fulfill(savedUser);
},
function(error){
logger.error("userService.update " + error);
reject(error);
});
}
});

UserModel.findOne({
"email": "[email protected]"
},
function(err, existingUser) {
if (err) {
logger.error("userService.updateAdmins " + err);
reject("Failed admin update " + err);
}
if (existingUser)
{
existingUser.merge({roles: [
1,
4
]});

validateUserAndSave(existingUser).then(function(savedUser){
fulfill(savedUser);
},
function(error){
logger.error("userService.updateAdmins " + error);
reject(error);
});
}
});

UserModel.findOne({
"email": "[email protected]"
},
function(err, existingUser) {
if (err) {
logger.error("userService.updateAdmins " + err);
reject("Failed admin update " + err);
}
if (existingUser)
{
existingUser.merge({roles: [
1,
4
]});

validateUserAndSave(existingUser).then(function(savedUser){
fulfill(savedUser);
},
function(error){
logger.error("userService.updateAdmins " + error);
reject(error);
});
}
});
});
};

exports.delete = function(userId) {
return new Promise(function(fulfill, reject) {
if (!userId) reject("User is missing. User deletion failed.");
Expand Down Expand Up @@ -590,6 +670,8 @@ exports.resetPassword = function(userEmail) {
if (!userEmail) reject("user email is missing");

UserModel.findOne({ email: userEmail }, function(err, existingUser) {
logger.debug(existingUser);

if (err) {
logger.error("userService.resetPassword " + err);
reject(err);
Expand All @@ -603,7 +685,8 @@ exports.resetPassword = function(userEmail) {

existingUser.activationHash = uuid.v4();
existingUser.password = newPassword;


logger.debug(newPassword);
existingUser.save(function(err, updatedUser) {
if (err) {
logger.error("userService.resetPassword " + err);
Expand Down
Loading

0 comments on commit a0757ef

Please sign in to comment.