Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
githubId: request.pre.user.githubId,
key: request.pre.keyHash.key
}, Config.get('/jwtSecret'), { algorithm: 'HS256', expiresIn: "1m" });
const _id = request.pre.user._id;
const update = {
socialLoginHash: request.pre.keyHash.hash
};
// EXPL: We update the user's social Id just in case they didn't have one yet
if (request.pre.user.facebookId) { update.facebookId = request.pre.user.facebookId }
if (request.pre.user.googleId) { update.googleId = request.pre.user.googleId }
if (request.pre.user.githubId) { update.githubId = request.pre.user.githubId }
return RestHapi.update(User, _id, update, Log)
.then(function(user) {
const redirectUrl = clientURL + '/login/social';
return reply.redirect(redirectUrl + '/?token=' + token);
})
.catch(function (error) {
Log.error(error);
return reply(Boom.gatewayTimeout('An error occurred.'));
});
};
const updateCurrentUserProfileHandler = function (request, reply) {
const _id = request.auth.credentials.user._id;
return RestHapi.update(User, _id, request.payload.profile, Log)
.then(function (user) {
return reply(user);
})
.catch(function (error) {
Log.error(error);
return reply(error);
});
};
const activateAccountHandler = function (request, reply) {
const _id = request.params._id;
return RestHapi.update(User, _id, { isActive: true }, Log)
.then(function (user) {
if (!user) {
return reply(Boom.notFound('Document not found. That is strange.'));
}
return reply(user);
})
.catch(function (error) {
Log.error(error);
return reply(RestHapi.errorHelper.formatResponse(error));
});
};
const disableAccountHandler = async function(request, h) {
try {
const _id = request.params._id
return await RestHapi.update(User, _id, { isEnabled: false }, Log)
} catch (err) {
errorHelper.handleError(err, Log)
}
}
const updateCurrentUserPasswordHandler = function (request, reply) {
const _id = request.auth.credentials.user._id;
return RestHapi.update(User, _id, { password: request.pre.password.hash, passwordUpdateRequired: false }, Log)
.then(function (user) {
return reply(user);
})
.catch(function (error) {
Log.error(error);
return reply(RestHapi.errorHelper.formatResponse(error));
});
};
pre: async function(payload, request, Log) {
try {
const Document = mongoose.model('document')
let document = await RestHapi.find(
Document,
request.params.ownerId,
{},
Log
)
const scope = document.scope
const userId = request.params.childId
Document.removeDocumentPermissions(scope, userId)
await RestHapi.update(Document, document._id, { scope }, Log)
return payload
} catch (err) {
errorHelper.handleError(err, Log)
}
}
}
.then(function (keyMatch) {
if (!keyMatch) {
reply(Boom.unauthorized('Invalid email or key.'));
throw 'Invalid email or key.'
}
const _id = request.pre.user._id;
const update = {
$unset: {
socialLoginHash: undefined
}
};
return RestHapi.update(User, _id, update, Log);
})
.then(function (user) {
.then(function (passwordHash) {
const _id = request.pre.user._id.toString();
const update = {
$set: {
password: passwordHash.hash
},
$unset: {
resetPassword: undefined
}
};
return RestHapi.update(User, _id, update);
})
.then(function (result) {
post: async function(document, request, result, logger) {
const Log = logger.bind()
try {
const User = mongoose.model('user')
if (!document.profileImageUrl) {
let profileImageUrl =
'https://www.gravatar.com/avatar/' +
document._id +
'?r=PG&d=robohash'
return await RestHapi.update(
User,
document._id,
{ profileImageUrl },
Log
)
} else {
return document
}
} catch (err) {
errorHelper.handleError(err, Log)
}
}
}
const updateCurrentUserProfileHandler = async function(request, h) {
try {
const _id = request.auth.credentials.user._id
return await RestHapi.update(User, _id, request.payload.profile, Log)
} catch (err) {
errorHelper.handleError(err, Log)
}
}