From ea2d98c9b6b861cf1af292b0c254528ee210360e Mon Sep 17 00:00:00 2001 From: NGPixel Date: Tue, 2 May 2017 21:04:55 -0400 Subject: [PATCH] feat: Admin + Uploads ctrl localization --- server/controllers/admin.js | 10 +++++----- server/controllers/uploads.js | 6 +++--- server/locales/en/errors.json | 13 ++++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/server/controllers/admin.js b/server/controllers/admin.js index 2ba7eebd..dd8975b6 100644 --- a/server/controllers/admin.js +++ b/server/controllers/admin.js @@ -167,11 +167,11 @@ router.post('/users/create', (req, res) => { router.post('/users/:id', (req, res) => { if (!res.locals.rights.manage) { - return res.status(401).json({ msg: 'Unauthorized' }) + return res.status(401).json({ msg: lang.t('errors:unauthorized') }) } if (!validator.isMongoId(req.params.id)) { - return res.status(400).json({ msg: 'Invalid User ID' }) + return res.status(400).json({ msg: lang.t('errors:invaliduserid') }) } return db.User.findById(req.params.id).then((usr) => { @@ -180,7 +180,7 @@ router.post('/users/:id', (req, res) => { if (usr.provider === 'local' && req.body.password !== '********') { let nPwd = _.trim(req.body.password) if (nPwd.length < 6) { - return Promise.reject(new Error('New Password too short!')) + return Promise.reject(new Error(lang.t('errors:newpasswordtooshort'))) } else { return db.User.hashPassword(nPwd).then((pwd) => { usr.password = pwd @@ -208,11 +208,11 @@ router.post('/users/:id', (req, res) => { */ router.delete('/users/:id', (req, res) => { if (!res.locals.rights.manage) { - return res.status(401).json({ msg: 'Unauthorized' }) + return res.status(401).json({ msg: lang.t('errors:unauthorized') }) } if (!validator.isMongoId(req.params.id)) { - return res.status(400).json({ msg: 'Invalid User ID' }) + return res.status(400).json({ msg: lang.t('errors:invaliduserid') }) } return db.User.findByIdAndRemove(req.params.id).then(() => { diff --git a/server/controllers/uploads.js b/server/controllers/uploads.js index 6e834507..437f8ec3 100644 --- a/server/controllers/uploads.js +++ b/server/controllers/uploads.js @@ -40,7 +40,7 @@ router.post('/img', lcdata.uploadImgHandler, (req, res, next) => { upl.validateUploadsFolder(destFolder).then((destFolderPath) => { if (!destFolderPath) { - res.json({ ok: false, msg: 'Invalid Folder' }) + res.json({ ok: false, msg: lang.t('errors:invalidfolder') }) return true } @@ -58,7 +58,7 @@ router.post('/img', lcdata.uploadImgHandler, (req, res, next) => { let mimeInfo = fileType(buf) if (!_.includes(['image/png', 'image/jpeg', 'image/gif', 'image/webp'], mimeInfo.mime)) { - return Promise.reject(new Error('Invalid file type.')) + return Promise.reject(new Error(lang.t('errors:invalidfiletype'))) } return true }).then(() => { @@ -97,7 +97,7 @@ router.post('/file', lcdata.uploadFileHandler, (req, res, next) => { upl.validateUploadsFolder(destFolder).then((destFolderPath) => { if (!destFolderPath) { - res.json({ ok: false, msg: 'Invalid Folder' }) + res.json({ ok: false, msg: lang.t('errors:invalidfolder') }) return true } diff --git a/server/locales/en/errors.json b/server/locales/en/errors.json index 97b1f842..6f7cbc01 100644 --- a/server/locales/en/errors.json +++ b/server/locales/en/errors.json @@ -1,16 +1,19 @@ { - "generic": "Oops, something went wrong", - "notexistdetail": "Would you like to create this entry?", + "alreadyexists": "This entry already exists!", + "debugmsg": "Detailed debug trail", "forbidden": "Forbidden", "forbiddendetail": "Sorry, you don't have the necessary permissions to access this page.", - "unauthorized": "Unauthorized", - "debugmsg": "Detailed debug trail", + "generic": "Oops, something went wrong", "invalidaction": "Invalid Action.", + "invalidfiletype": "Invalid File Type.", + "invalidfolder": "Invalid Folder.", "invalidpath": "Invalid page path.", "invaliduserid": "Invalid User Id", + "newpasswordtooshort": "New password is too short!", + "notexistdetail": "Would you like to create this entry?", "reservedname": "You cannot create a document with this name as it is reserved by the system.", - "alreadyexists": "This entry already exists!", "starterfailed": "Could not load starter content!", + "unauthorized": "Unauthorized", "actions": { "create": "Create", "gohome": "Go Home",