Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.changePassword = async (req, res) => {
try {
const id = await utils.isIDGood(req.user._id)
const user = await findUser(id)
req = matchedData(req)
const isPasswordMatch = await auth.checkPassword(req.oldPassword, user)
if (!isPasswordMatch) {
utils.handleError(res, await passwordsDoNotMatch())
} else {
// all ok, proceed to change password
res.status(200).json(await changePasswordInDB(id, req))
}
} catch (error) {
utils.handleError(res, error)
}
}
function deleteStackExec(request, response) {
// Build request params
const { user } = request;
const params = matchedData(request);
const { projectKey, name } = params;
return stackRepository.userCanDeleteStack(projectKey, user, name)
.then((result) => {
if (result) {
// Handle request
return stackManager.deleteStack(user, params)
.then(controllerHelper.sendSuccessfulDeletion(response))
.catch(controllerHelper.handleError(response, 'deleting', TYPE, params.name));
}
return Promise.reject();
})
.catch(controllerHelper.handleError(response, 'deleting', TYPE, params.name));
}
function getOneByNameExec(request, response) {
// Build request params
const { user } = request;
const params = matchedData(request);
// Handle request
return stackRepository.getOneByName(params.projectKey, user, params.name)
.then(handleId)
.then(stack => response.send(stack))
.catch(controllerHelper.handleError(response, 'matching Name for', TYPE, undefined));
}
exports.forgotPassword = async (req, res) => {
try {
// Gets locale from header 'Accept-Language'
const locale = req.getLocale()
const data = matchedData(req)
await findUser(data.email)
const item = await saveForgotPassword(req)
emailer.sendResetPasswordEmailMessage(locale, item)
res.status(200).json(forgotPasswordResponse(item))
} catch (error) {
utils.handleError(res, error)
}
}
async create(req, res) {
const user = await UserRepository.setTransformer(UserTransformer).create(matchedData(req))
this.sendResponse(res, user)
}
async function removeUsers(request, response, next) {
const { projectKey, name, userIds } = matchedData(request);
try {
const volume = await dataStorageRepository.removeUsers(request.user, projectKey, name, userIds);
response.send(volume);
} catch (error) {
next(new Error(`Unable to remove users from project ${projectKey} volume ${name}: ${error.message}`));
}
}
exports.updateItem = async (req, res) => {
try {
req = matchedData(req)
const id = await utils.isIDGood(req.id)
const doesEmailExists = await emailer.emailExistsExcludingMyself(
id,
req.email
)
if (!doesEmailExists) {
res.status(200).json(await db.updateItem(id, model, req))
}
} catch (error) {
utils.handleError(res, error)
}
}
function listByCategoryExec(request, response) {
const { user } = request;
const params = matchedData(request);
return stackRepository.getAllByCategory(params.projectKey, user, params.category)
.then(mapHandleId)
.then(stacks => response.send(stacks))
.catch(controllerHelper.handleError(response, 'retrieving by category for', TYPE, undefined));
}
async function listProjectActiveVolumes(request, response) {
const { projectKey } = matchedData(request);
const volumes = await dataStorageRepository.getAllProjectActive(request.user, projectKey);
response.send(volumes);
}
async function getProjectByKey(request, response, next) {
const { projectKey } = matchedData(request);
try {
const project = await projectsRepository.getByKey(projectKey);
if (project) {
response.send(project);
} else {
response.status(404).send();
}
} catch (error) {
next(new Error(`Error getting project by key: ${error.message}`));
}
}