parent
a3541d887b
commit
3cc7ec63e8
@ -1,212 +1,156 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const user = require('../../user');
|
||||||
|
const meta = require('../../meta');
|
||||||
var db = require('../../database');
|
const plugins = require('../../plugins');
|
||||||
var user = require('../../user');
|
const helpers = require('../helpers');
|
||||||
var meta = require('../../meta');
|
const groups = require('../../groups');
|
||||||
var plugins = require('../../plugins');
|
const accountHelpers = require('./helpers');
|
||||||
var helpers = require('../helpers');
|
const privileges = require('../../privileges');
|
||||||
var groups = require('../../groups');
|
const file = require('../../file');
|
||||||
var accountHelpers = require('./helpers');
|
|
||||||
var privileges = require('../../privileges');
|
const editController = module.exports;
|
||||||
var file = require('../../file');
|
|
||||||
|
editController.get = async function (req, res, next) {
|
||||||
var editController = module.exports;
|
const [userData, canUseSignature] = await Promise.all([
|
||||||
|
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid),
|
||||||
editController.get = function (req, res, callback) {
|
privileges.global.can('signature', req.uid),
|
||||||
async.waterfall([
|
]);
|
||||||
function (next) {
|
if (!userData) {
|
||||||
async.parallel({
|
return next();
|
||||||
userData: function (next) {
|
}
|
||||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
userData.maximumSignatureLength = meta.config.maximumSignatureLength;
|
||||||
},
|
userData.maximumAboutMeLength = meta.config.maximumAboutMeLength;
|
||||||
canUseSignature: function (next) {
|
userData.maximumProfileImageSize = meta.config.maximumProfileImageSize;
|
||||||
privileges.global.can('signature', req.uid, next);
|
userData.allowProfilePicture = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:profile-picture'];
|
||||||
},
|
userData.allowCoverPicture = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:cover-picture'];
|
||||||
}, next);
|
userData.allowProfileImageUploads = meta.config.allowProfileImageUploads;
|
||||||
},
|
userData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
|
||||||
function (results, next) {
|
userData.allowAccountDelete = meta.config.allowAccountDelete === 1;
|
||||||
var userData = results.userData;
|
userData.allowWebsite = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:website'];
|
||||||
if (!userData) {
|
userData.allowAboutMe = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:aboutme'];
|
||||||
return callback();
|
userData.allowSignature = canUseSignature && (!userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:signature']);
|
||||||
}
|
userData.profileImageDimension = meta.config.profileImageDimension;
|
||||||
userData.maximumSignatureLength = meta.config.maximumSignatureLength;
|
userData.defaultAvatar = user.getDefaultAvatar();
|
||||||
userData.maximumAboutMeLength = meta.config.maximumAboutMeLength;
|
|
||||||
userData.maximumProfileImageSize = meta.config.maximumProfileImageSize;
|
userData.groups = userData.groups.filter(g => g && g.userTitleEnabled && !groups.isPrivilegeGroup(g.name) && g.name !== 'registered-users');
|
||||||
userData.allowProfilePicture = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:profile-picture'];
|
|
||||||
userData.allowCoverPicture = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:cover-picture'];
|
if (!userData.allowMultipleBadges) {
|
||||||
userData.allowProfileImageUploads = meta.config.allowProfileImageUploads;
|
userData.groupTitle = userData.groupTitleArray[0];
|
||||||
userData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
|
}
|
||||||
userData.allowAccountDelete = meta.config.allowAccountDelete === 1;
|
userData.groups.forEach(function (group) {
|
||||||
userData.allowWebsite = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:website'];
|
group.selected = userData.groupTitleArray.includes(group.name);
|
||||||
userData.allowAboutMe = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:aboutme'];
|
});
|
||||||
userData.allowSignature = results.canUseSignature && (!userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:signature']);
|
|
||||||
userData.profileImageDimension = meta.config.profileImageDimension;
|
userData.title = '[[pages:account/edit, ' + userData.username + ']]';
|
||||||
userData.defaultAvatar = user.getDefaultAvatar();
|
userData.breadcrumbs = helpers.buildBreadcrumbs([
|
||||||
|
{
|
||||||
userData.groups = userData.groups.filter(function (group) {
|
text: userData.username,
|
||||||
return group && group.userTitleEnabled && !groups.isPrivilegeGroup(group.name) && group.name !== 'registered-users';
|
url: '/user/' + userData.userslug,
|
||||||
});
|
|
||||||
|
|
||||||
if (!userData.allowMultipleBadges) {
|
|
||||||
userData.groupTitle = userData.groupTitleArray[0];
|
|
||||||
}
|
|
||||||
userData.groups.forEach(function (group) {
|
|
||||||
group.selected = userData.groupTitleArray.includes(group.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
userData.title = '[[pages:account/edit, ' + userData.username + ']]';
|
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([
|
|
||||||
{
|
|
||||||
text: userData.username,
|
|
||||||
url: '/user/' + userData.userslug,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: '[[user:edit]]',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
userData.editButtons = [];
|
|
||||||
|
|
||||||
plugins.fireHook('filter:user.account.edit', userData, next);
|
|
||||||
},
|
},
|
||||||
function (userData) {
|
{
|
||||||
res.render('account/edit', userData);
|
text: '[[user:edit]]',
|
||||||
},
|
},
|
||||||
], callback);
|
]);
|
||||||
};
|
userData.editButtons = [];
|
||||||
|
|
||||||
editController.password = function (req, res, next) {
|
const result = await plugins.fireHook('filter:user.account.edit', userData);
|
||||||
renderRoute('password', req, res, next);
|
res.render('account/edit', result);
|
||||||
};
|
};
|
||||||
|
|
||||||
editController.username = function (req, res, next) {
|
editController.password = async function (req, res, next) {
|
||||||
renderRoute('username', req, res, next);
|
await renderRoute('password', req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
editController.email = function (req, res, next) {
|
editController.username = async function (req, res, next) {
|
||||||
renderRoute('email', req, res, next);
|
await renderRoute('username', req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderRoute(name, req, res, next) {
|
editController.email = async function (req, res, next) {
|
||||||
async.waterfall([
|
await renderRoute('email', req, res, next);
|
||||||
function (next) {
|
};
|
||||||
getUserData(req, next, next);
|
|
||||||
},
|
|
||||||
function (userData) {
|
|
||||||
if (!userData) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (meta.config[name + ':disableEdit'] && !userData.isAdmin) {
|
|
||||||
return helpers.notAllowed(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name === 'password') {
|
|
||||||
userData.minimumPasswordLength = meta.config.minimumPasswordLength;
|
|
||||||
userData.minimumPasswordStrength = meta.config.minimumPasswordStrength;
|
|
||||||
}
|
|
||||||
|
|
||||||
userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]';
|
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([
|
|
||||||
{
|
|
||||||
text: userData.username,
|
|
||||||
url: '/user/' + userData.userslug,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: '[[user:edit]]',
|
|
||||||
url: '/user/' + userData.userslug + '/edit',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: '[[user:' + name + ']]',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
res.render('account/edit/' + name, userData);
|
|
||||||
},
|
|
||||||
], next);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUserData(req, next, callback) {
|
async function renderRoute(name, req, res, next) {
|
||||||
var userData;
|
const userData = await getUserData(req, next);
|
||||||
async.waterfall([
|
if (!userData) {
|
||||||
function (next) {
|
return next();
|
||||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
}
|
||||||
|
if (meta.config[name + ':disableEdit'] && !userData.isAdmin) {
|
||||||
|
return helpers.notAllowed(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name === 'password') {
|
||||||
|
userData.minimumPasswordLength = meta.config.minimumPasswordLength;
|
||||||
|
userData.minimumPasswordStrength = meta.config.minimumPasswordStrength;
|
||||||
|
}
|
||||||
|
|
||||||
|
userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]';
|
||||||
|
userData.breadcrumbs = helpers.buildBreadcrumbs([
|
||||||
|
{
|
||||||
|
text: userData.username,
|
||||||
|
url: '/user/' + userData.userslug,
|
||||||
},
|
},
|
||||||
function (data, next) {
|
{
|
||||||
userData = data;
|
text: '[[user:edit]]',
|
||||||
if (!userData) {
|
url: '/user/' + userData.userslug + '/edit',
|
||||||
return callback(null, null);
|
|
||||||
}
|
|
||||||
db.getObjectField('user:' + userData.uid, 'password', next);
|
|
||||||
},
|
},
|
||||||
function (password, next) {
|
{
|
||||||
userData.hasPassword = !!password;
|
text: '[[user:' + name + ']]',
|
||||||
next(null, userData);
|
|
||||||
},
|
},
|
||||||
], callback);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
editController.uploadPicture = function (req, res, next) {
|
res.render('account/edit/' + name, userData);
|
||||||
var userPhoto = req.files.files[0];
|
}
|
||||||
|
|
||||||
var updateUid;
|
async function getUserData(req) {
|
||||||
|
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||||
|
if (!userData) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
async.waterfall([
|
userData.hasPassword = await user.hasPassword(userData.uid);
|
||||||
function (next) {
|
return userData;
|
||||||
user.getUidByUserslug(req.params.userslug, next);
|
}
|
||||||
},
|
|
||||||
function (uid, next) {
|
|
||||||
updateUid = uid;
|
|
||||||
|
|
||||||
privileges.users.canEdit(req.uid, uid, next);
|
editController.uploadPicture = async function (req, res, next) {
|
||||||
},
|
const userPhoto = req.files.files[0];
|
||||||
function (isAllowed, next) {
|
try {
|
||||||
if (!isAllowed) {
|
const updateUid = await user.getUidByUserslug(req.params.userslug);
|
||||||
return helpers.notAllowed(req, res);
|
const isAllowed = await privileges.users.canEdit(req.uid, updateUid);
|
||||||
}
|
if (!isAllowed) {
|
||||||
user.checkMinReputation(req.uid, updateUid, 'min:rep:profile-picture', next);
|
return helpers.notAllowed(req, res);
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
user.uploadCroppedPicture({
|
|
||||||
uid: updateUid,
|
|
||||||
file: userPhoto,
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
], function (err, image) {
|
|
||||||
file.delete(userPhoto.path);
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
}
|
||||||
|
await user.checkMinReputation(req.uid, updateUid, 'min:rep:profile-picture');
|
||||||
|
const image = await user.uploadCroppedPicture({
|
||||||
|
uid: updateUid,
|
||||||
|
file: userPhoto,
|
||||||
|
});
|
||||||
res.json([{
|
res.json([{
|
||||||
name: userPhoto.name,
|
name: userPhoto.name,
|
||||||
url: image.url,
|
url: image.url,
|
||||||
}]);
|
}]);
|
||||||
});
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
} finally {
|
||||||
|
file.delete(userPhoto.path);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
editController.uploadCoverPicture = function (req, res, next) {
|
editController.uploadCoverPicture = async function (req, res, next) {
|
||||||
var params = JSON.parse(req.body.params);
|
var params = JSON.parse(req.body.params);
|
||||||
var coverPhoto = req.files.files[0];
|
var coverPhoto = req.files.files[0];
|
||||||
|
try {
|
||||||
async.waterfall([
|
await user.checkMinReputation(req.uid, params.uid, 'min:rep:cover-picture');
|
||||||
function (next) {
|
const image = await user.updateCoverPicture({
|
||||||
user.checkMinReputation(req.uid, params.uid, 'min:rep:cover-picture', next);
|
file: coverPhoto,
|
||||||
},
|
uid: params.uid,
|
||||||
function (next) {
|
});
|
||||||
user.updateCoverPicture({
|
|
||||||
file: coverPhoto,
|
|
||||||
uid: params.uid,
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
], function (err, image) {
|
|
||||||
file.delete(coverPhoto.path);
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
res.json([{
|
res.json([{
|
||||||
url: image.url,
|
url: image.url,
|
||||||
}]);
|
}]);
|
||||||
});
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
} finally {
|
||||||
|
file.delete(coverPhoto.path);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,80 +1,59 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const util = require('util');
|
||||||
|
|
||||||
var db = require('../../database');
|
const db = require('../../database');
|
||||||
var user = require('../../user');
|
const user = require('../../user');
|
||||||
var helpers = require('../helpers');
|
const helpers = require('../helpers');
|
||||||
var accountHelpers = require('./helpers');
|
const accountHelpers = require('./helpers');
|
||||||
|
|
||||||
var sessionController = module.exports;
|
const sessionController = module.exports;
|
||||||
|
|
||||||
sessionController.get = function (req, res, callback) {
|
sessionController.get = async function (req, res, next) {
|
||||||
var userData;
|
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||||
|
if (!userData) {
|
||||||
async.waterfall([
|
return next();
|
||||||
function (next) {
|
}
|
||||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
|
||||||
},
|
|
||||||
function (_userData, next) {
|
|
||||||
userData = _userData;
|
|
||||||
if (!userData) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
user.auth.getSessions(userData.uid, req.sessionID, next);
|
|
||||||
},
|
|
||||||
function (sessions) {
|
|
||||||
userData.sessions = sessions;
|
|
||||||
|
|
||||||
userData.title = '[[pages:account/sessions]]';
|
userData.sessions = await user.auth.getSessions(userData.uid, req.sessionID);
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[pages:account/sessions]]' }]);
|
userData.title = '[[pages:account/sessions]]';
|
||||||
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[pages:account/sessions]]' }]);
|
||||||
|
|
||||||
res.render('account/sessions', userData);
|
res.render('account/sessions', userData);
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sessionController.revoke = function (req, res, next) {
|
const getSessionAsync = util.promisify(function (sid, callback) {
|
||||||
|
db.sessionStore.get(sid, (err, sessionObj) => callback(err, sessionObj || null));
|
||||||
|
});
|
||||||
|
|
||||||
|
sessionController.revoke = async function (req, res, next) {
|
||||||
if (!req.params.hasOwnProperty('uuid')) {
|
if (!req.params.hasOwnProperty('uuid')) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
var _id;
|
const uid = await user.getUidByUserslug(req.params.userslug);
|
||||||
var uid = res.locals.uid;
|
if (!uid) {
|
||||||
async.waterfall([
|
throw new Error('[[error:no-session-found]]');
|
||||||
function (next) {
|
}
|
||||||
if (!uid) {
|
const sids = await db.getSortedSetRange('uid:' + uid + ':sessions', 0, -1);
|
||||||
return next(new Error('[[error:no-session-found]]'));
|
let _id;
|
||||||
}
|
for (const sid of sids) {
|
||||||
db.getSortedSetRange('uid:' + uid + ':sessions', 0, -1, next);
|
/* eslint-disable no-await-in-loop */
|
||||||
},
|
const sessionObj = await getSessionAsync(sid);
|
||||||
function (sids, done) {
|
if (sessionObj && sessionObj.meta && sessionObj.meta.uuid === req.params.uuid) {
|
||||||
async.eachSeries(sids, function (sid, next) {
|
_id = sid;
|
||||||
db.sessionStore.get(sid, function (err, sessionObj) {
|
break;
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
if (sessionObj && sessionObj.meta && sessionObj.meta.uuid === req.params.uuid) {
|
|
||||||
_id = sid;
|
|
||||||
done();
|
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
if (!_id) {
|
|
||||||
return next(new Error('[[error:no-session-found]]'));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user.auth.revokeSession(_id, uid, next);
|
if (!_id) {
|
||||||
},
|
throw new Error('[[error:no-session-found]]');
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
return res.status(500).send(err.message);
|
|
||||||
}
|
}
|
||||||
return res.sendStatus(200);
|
|
||||||
});
|
await user.auth.revokeSession(_id, uid);
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(500).send(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.sendStatus(200);
|
||||||
};
|
};
|
||||||
|
@ -1,356 +1,306 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const nconf = require('nconf');
|
||||||
var nconf = require('nconf');
|
const winston = require('winston');
|
||||||
var winston = require('winston');
|
const _ = require('lodash');
|
||||||
var _ = require('lodash');
|
const jwt = require('jsonwebtoken');
|
||||||
var jwt = require('jsonwebtoken');
|
const util = require('util');
|
||||||
|
|
||||||
var user = require('../../user');
|
const user = require('../../user');
|
||||||
var languages = require('../../languages');
|
const languages = require('../../languages');
|
||||||
var meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
var plugins = require('../../plugins');
|
const plugins = require('../../plugins');
|
||||||
var privileges = require('../../privileges');
|
const privileges = require('../../privileges');
|
||||||
var categories = require('../../categories');
|
const categories = require('../../categories');
|
||||||
var notifications = require('../../notifications');
|
const notifications = require('../../notifications');
|
||||||
var db = require('../../database');
|
const db = require('../../database');
|
||||||
var helpers = require('../helpers');
|
const helpers = require('../helpers');
|
||||||
var accountHelpers = require('./helpers');
|
const accountHelpers = require('./helpers');
|
||||||
|
|
||||||
var settingsController = module.exports;
|
const settingsController = module.exports;
|
||||||
|
|
||||||
settingsController.get = function (req, res, callback) {
|
settingsController.get = async function (req, res, next) {
|
||||||
var userData;
|
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||||
async.waterfall([
|
if (!userData) {
|
||||||
function (next) {
|
return next();
|
||||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
}
|
||||||
},
|
const [settings, languagesData, soundsMapping] = await Promise.all([
|
||||||
function (_userData, next) {
|
user.getSettings(userData.uid),
|
||||||
userData = _userData;
|
languages.list(),
|
||||||
if (!userData) {
|
meta.sounds.getUserSoundMap(userData.uid),
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
async.parallel({
|
|
||||||
settings: function (next) {
|
|
||||||
user.getSettings(userData.uid, next);
|
|
||||||
},
|
|
||||||
languages: function (next) {
|
|
||||||
languages.list(next);
|
|
||||||
},
|
|
||||||
soundsMapping: function (next) {
|
|
||||||
meta.sounds.getUserSoundMap(userData.uid, next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
userData.settings = results.settings;
|
|
||||||
userData.languages = results.languages;
|
|
||||||
if (userData.isAdmin && userData.isSelf) {
|
|
||||||
userData.acpLanguages = _.cloneDeep(results.languages);
|
|
||||||
}
|
|
||||||
|
|
||||||
var types = [
|
|
||||||
'notification',
|
|
||||||
'chat-incoming',
|
|
||||||
'chat-outgoing',
|
|
||||||
];
|
|
||||||
var aliases = {
|
|
||||||
notification: 'notificationSound',
|
|
||||||
'chat-incoming': 'incomingChatSound',
|
|
||||||
'chat-outgoing': 'outgoingChatSound',
|
|
||||||
};
|
|
||||||
|
|
||||||
types.forEach(function (type) {
|
]);
|
||||||
var soundpacks = plugins.soundpacks.map(function (pack) {
|
|
||||||
var sounds = Object.keys(pack.sounds).map(function (soundName) {
|
|
||||||
var value = pack.name + ' | ' + soundName;
|
|
||||||
return {
|
|
||||||
name: soundName,
|
|
||||||
value: value,
|
|
||||||
selected: value === results.soundsMapping[type],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: pack.name,
|
|
||||||
sounds: sounds,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
userData[type + '-sound'] = soundpacks;
|
|
||||||
// fallback
|
|
||||||
userData[aliases[type]] = soundpacks.concat.apply([], soundpacks.map(function (pack) {
|
|
||||||
return pack.sounds.map(function (sound) {
|
|
||||||
return {
|
|
||||||
name: sound.value,
|
|
||||||
selected: sound.selected,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.fireHook('filter:user.customSettings', { settings: results.settings, customSettings: [], uid: req.uid }, next);
|
userData.settings = settings;
|
||||||
},
|
userData.languages = languagesData;
|
||||||
function (data, next) {
|
if (userData.isAdmin && userData.isSelf) {
|
||||||
userData.customSettings = data.customSettings;
|
userData.acpLanguages = _.cloneDeep(languagesData);
|
||||||
async.parallel({
|
}
|
||||||
notificationSettings: function (next) {
|
|
||||||
getNotificationSettings(userData, next);
|
|
||||||
},
|
|
||||||
routes: function (next) {
|
|
||||||
getHomePageRoutes(userData, next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results) {
|
|
||||||
userData.homePageRoutes = results.routes;
|
|
||||||
userData.notificationSettings = results.notificationSettings;
|
|
||||||
userData.disableEmailSubscriptions = meta.config.disableEmailSubscriptions;
|
|
||||||
|
|
||||||
userData.dailyDigestFreqOptions = [
|
|
||||||
{ value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
|
|
||||||
{ value: 'day', name: '[[user:digest_daily]]', selected: userData.settings.dailyDigestFreq === 'day' },
|
|
||||||
{ value: 'week', name: '[[user:digest_weekly]]', selected: userData.settings.dailyDigestFreq === 'week' },
|
|
||||||
{ value: 'month', name: '[[user:digest_monthly]]', selected: userData.settings.dailyDigestFreq === 'month' },
|
|
||||||
];
|
|
||||||
|
|
||||||
userData.bootswatchSkinOptions = [
|
|
||||||
{ name: 'Default', value: '' },
|
|
||||||
{ name: 'Cerulean', value: 'cerulean' },
|
|
||||||
{ name: 'Cosmo', value: 'cosmo' },
|
|
||||||
{ name: 'Cyborg', value: 'cyborg' },
|
|
||||||
{ name: 'Darkly', value: 'darkly' },
|
|
||||||
{ name: 'Flatly', value: 'flatly' },
|
|
||||||
{ name: 'Journal', value: 'journal' },
|
|
||||||
{ name: 'Lumen', value: 'lumen' },
|
|
||||||
{ name: 'Paper', value: 'paper' },
|
|
||||||
{ name: 'Readable', value: 'readable' },
|
|
||||||
{ name: 'Sandstone', value: 'sandstone' },
|
|
||||||
{ name: 'Simplex', value: 'simplex' },
|
|
||||||
{ name: 'Slate', value: 'slate' },
|
|
||||||
{ name: 'Spacelab', value: 'spacelab' },
|
|
||||||
{ name: 'Superhero', value: 'superhero' },
|
|
||||||
{ name: 'United', value: 'united' },
|
|
||||||
{ name: 'Yeti', value: 'yeti' },
|
|
||||||
];
|
|
||||||
|
|
||||||
userData.bootswatchSkinOptions.forEach(function (skin) {
|
|
||||||
skin.selected = skin.value === userData.settings.bootswatchSkin;
|
|
||||||
});
|
|
||||||
|
|
||||||
userData.languages.forEach(function (language) {
|
addSoundSettings(userData, soundsMapping);
|
||||||
language.selected = language.code === userData.settings.userLang;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (userData.isAdmin && userData.isSelf) {
|
const data = await plugins.fireHook('filter:user.customSettings', {
|
||||||
userData.acpLanguages.forEach(function (language) {
|
settings: settings,
|
||||||
language.selected = language.code === userData.settings.acpLang;
|
customSettings: [],
|
||||||
});
|
uid: req.uid,
|
||||||
}
|
});
|
||||||
|
|
||||||
var notifFreqOptions = [
|
|
||||||
'all',
|
|
||||||
'first',
|
|
||||||
'everyTen',
|
|
||||||
'threshold',
|
|
||||||
'logarithmic',
|
|
||||||
'disabled',
|
|
||||||
];
|
|
||||||
|
|
||||||
userData.upvoteNotifFreq = notifFreqOptions.map(function (name) {
|
|
||||||
return {
|
|
||||||
name: name,
|
|
||||||
selected: name === userData.settings.upvoteNotifFreq,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
userData.categoryWatchState = { [userData.settings.categoryWatchState]: true };
|
const [notificationSettings, routes] = await Promise.all([
|
||||||
|
getNotificationSettings(userData),
|
||||||
|
getHomePageRoutes(userData),
|
||||||
|
]);
|
||||||
|
|
||||||
|
userData.customSettings = data.customSettings;
|
||||||
|
userData.homePageRoutes = routes;
|
||||||
|
userData.notificationSettings = notificationSettings;
|
||||||
|
userData.disableEmailSubscriptions = meta.config.disableEmailSubscriptions;
|
||||||
|
|
||||||
|
userData.dailyDigestFreqOptions = [
|
||||||
|
{ value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
|
||||||
|
{ value: 'day', name: '[[user:digest_daily]]', selected: userData.settings.dailyDigestFreq === 'day' },
|
||||||
|
{ value: 'week', name: '[[user:digest_weekly]]', selected: userData.settings.dailyDigestFreq === 'week' },
|
||||||
|
{ value: 'month', name: '[[user:digest_monthly]]', selected: userData.settings.dailyDigestFreq === 'month' },
|
||||||
|
];
|
||||||
|
|
||||||
|
userData.bootswatchSkinOptions = [
|
||||||
|
{ name: 'Default', value: '' },
|
||||||
|
{ name: 'Cerulean', value: 'cerulean' },
|
||||||
|
{ name: 'Cosmo', value: 'cosmo' },
|
||||||
|
{ name: 'Cyborg', value: 'cyborg' },
|
||||||
|
{ name: 'Darkly', value: 'darkly' },
|
||||||
|
{ name: 'Flatly', value: 'flatly' },
|
||||||
|
{ name: 'Journal', value: 'journal' },
|
||||||
|
{ name: 'Lumen', value: 'lumen' },
|
||||||
|
{ name: 'Paper', value: 'paper' },
|
||||||
|
{ name: 'Readable', value: 'readable' },
|
||||||
|
{ name: 'Sandstone', value: 'sandstone' },
|
||||||
|
{ name: 'Simplex', value: 'simplex' },
|
||||||
|
{ name: 'Slate', value: 'slate' },
|
||||||
|
{ name: 'Spacelab', value: 'spacelab' },
|
||||||
|
{ name: 'Superhero', value: 'superhero' },
|
||||||
|
{ name: 'United', value: 'united' },
|
||||||
|
{ name: 'Yeti', value: 'yeti' },
|
||||||
|
];
|
||||||
|
|
||||||
|
userData.bootswatchSkinOptions.forEach(function (skin) {
|
||||||
|
skin.selected = skin.value === userData.settings.bootswatchSkin;
|
||||||
|
});
|
||||||
|
|
||||||
userData.disableCustomUserSkins = meta.config.disableCustomUserSkins;
|
userData.languages.forEach(function (language) {
|
||||||
|
language.selected = language.code === userData.settings.userLang;
|
||||||
|
});
|
||||||
|
|
||||||
userData.allowUserHomePage = meta.config.allowUserHomePage;
|
if (userData.isAdmin && userData.isSelf) {
|
||||||
|
userData.acpLanguages.forEach(function (language) {
|
||||||
|
language.selected = language.code === userData.settings.acpLang;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
userData.hideFullname = meta.config.hideFullname;
|
const notifFreqOptions = [
|
||||||
userData.hideEmail = meta.config.hideEmail;
|
'all',
|
||||||
|
'first',
|
||||||
|
'everyTen',
|
||||||
|
'threshold',
|
||||||
|
'logarithmic',
|
||||||
|
'disabled',
|
||||||
|
];
|
||||||
|
|
||||||
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
|
userData.upvoteNotifFreq = notifFreqOptions.map(name => ({ name: name, selected: name === userData.settings.upvoteNotifFreq }));
|
||||||
|
|
||||||
userData.maxTopicsPerPage = meta.config.maxTopicsPerPage;
|
userData.categoryWatchState = { [userData.settings.categoryWatchState]: true };
|
||||||
userData.maxPostsPerPage = meta.config.maxPostsPerPage;
|
|
||||||
|
|
||||||
userData.title = '[[pages:account/settings]]';
|
userData.disableCustomUserSkins = meta.config.disableCustomUserSkins;
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
|
|
||||||
|
|
||||||
res.render('account/settings', userData);
|
userData.allowUserHomePage = meta.config.allowUserHomePage;
|
||||||
},
|
|
||||||
], callback);
|
userData.hideFullname = meta.config.hideFullname;
|
||||||
|
userData.hideEmail = meta.config.hideEmail;
|
||||||
|
|
||||||
|
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
|
||||||
|
|
||||||
|
userData.maxTopicsPerPage = meta.config.maxTopicsPerPage;
|
||||||
|
userData.maxPostsPerPage = meta.config.maxPostsPerPage;
|
||||||
|
|
||||||
|
userData.title = '[[pages:account/settings]]';
|
||||||
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
|
||||||
|
|
||||||
|
res.render('account/settings', userData);
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsController.unsubscribe = function (req, res) {
|
function addSoundSettings(userData, soundsMapping) {
|
||||||
|
const types = [
|
||||||
|
'notification',
|
||||||
|
'chat-incoming',
|
||||||
|
'chat-outgoing',
|
||||||
|
];
|
||||||
|
const aliases = {
|
||||||
|
notification: 'notificationSound',
|
||||||
|
'chat-incoming': 'incomingChatSound',
|
||||||
|
'chat-outgoing': 'outgoingChatSound',
|
||||||
|
};
|
||||||
|
|
||||||
|
types.forEach(function (type) {
|
||||||
|
const soundpacks = plugins.soundpacks.map(function (pack) {
|
||||||
|
const sounds = Object.keys(pack.sounds).map(function (soundName) {
|
||||||
|
const value = pack.name + ' | ' + soundName;
|
||||||
|
return {
|
||||||
|
name: soundName,
|
||||||
|
value: value,
|
||||||
|
selected: value === soundsMapping[type],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: pack.name,
|
||||||
|
sounds: sounds,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
userData[type + '-sound'] = soundpacks;
|
||||||
|
// fallback
|
||||||
|
userData[aliases[type]] = soundpacks.concat.apply([], soundpacks.map(function (pack) {
|
||||||
|
return pack.sounds.map(function (sound) {
|
||||||
|
return {
|
||||||
|
name: sound.value,
|
||||||
|
selected: sound.selected,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const jwtVerifyAsync = util.promisify(function (token, callback) {
|
||||||
|
jwt.verify(token, nconf.get('secret'), (err, payload) => callback(err, payload));
|
||||||
|
});
|
||||||
|
|
||||||
|
settingsController.unsubscribe = async function (req, res) {
|
||||||
if (!req.params.token) {
|
if (!req.params.token) {
|
||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
}
|
}
|
||||||
|
let payload;
|
||||||
jwt.verify(req.params.token, nconf.get('secret'), function (err, payload) {
|
try {
|
||||||
if (err) {
|
payload = await jwtVerifyAsync(req.params.token);
|
||||||
return res.sendStatus(403);
|
if (!payload || (payload.template !== 'notification' && payload.template !== 'digest')) {
|
||||||
|
return res.sendStatus(404);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
switch (payload.template) {
|
return res.sendStatus(403);
|
||||||
case 'digest':
|
}
|
||||||
async.parallel([
|
try {
|
||||||
async.apply(user.setSetting, payload.uid, 'dailyDigestFreq', 'off'),
|
if (payload.template === 'digest') {
|
||||||
async.apply(user.updateDigestSetting, payload.uid, 'off'),
|
await Promise.all([
|
||||||
], function (err) {
|
user.setSetting(payload.uid, 'dailyDigestFreq', 'off'),
|
||||||
if (err) {
|
user.updateDigestSetting(payload.uid, 'off'),
|
||||||
winston.error('[settings/unsubscribe] One-click unsubscribe failed with error: ' + err.message);
|
]);
|
||||||
return res.sendStatus(500);
|
} else if (payload.template === 'notification') {
|
||||||
}
|
const current = await db.getObjectField('user:' + payload.uid + ':settings', 'notificationType_' + payload.type);
|
||||||
|
await user.setSetting(payload.uid, 'notificationType_' + payload.type, (current === 'notificationemail' ? 'notification' : 'none'));
|
||||||
return res.sendStatus(200);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 'notification':
|
|
||||||
async.waterfall([
|
|
||||||
async.apply(db.getObjectField, 'user:' + payload.uid + ':settings', 'notificationType_' + payload.type),
|
|
||||||
(current, next) => {
|
|
||||||
user.setSetting(payload.uid, 'notificationType_' + payload.type, (current === 'notificationemail' ? 'notification' : 'none'), next);
|
|
||||||
},
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
winston.error('[settings/unsubscribe] One-click unsubscribe failed with error: ' + err.message);
|
|
||||||
return res.sendStatus(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.sendStatus(200);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res.sendStatus(404);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
res.sendStatus(200);
|
||||||
|
} catch (err) {
|
||||||
|
winston.error('[settings/unsubscribe] One-click unsubscribe failed with error: ' + err.message);
|
||||||
|
res.sendStatus(500);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function getNotificationSettings(userData, callback) {
|
async function getNotificationSettings(userData) {
|
||||||
var privilegedTypes = [];
|
const privilegedTypes = [];
|
||||||
|
|
||||||
async.waterfall([
|
const privileges = await user.getPrivileges(userData.uid);
|
||||||
function (next) {
|
if (privileges.isAdmin) {
|
||||||
user.getPrivileges(userData.uid, next);
|
privilegedTypes.push('notificationType_new-register');
|
||||||
},
|
}
|
||||||
function (privileges, next) {
|
if (privileges.isAdmin || privileges.isGlobalMod || privileges.isModeratorOfAnyCategory) {
|
||||||
if (privileges.isAdmin) {
|
privilegedTypes.push('notificationType_post-queue', 'notificationType_new-post-flag');
|
||||||
privilegedTypes.push('notificationType_new-register');
|
}
|
||||||
}
|
if (privileges.isAdmin || privileges.isGlobalMod) {
|
||||||
if (privileges.isAdmin || privileges.isGlobalMod || privileges.isModeratorOfAnyCategory) {
|
privilegedTypes.push('notificationType_new-user-flag');
|
||||||
privilegedTypes.push('notificationType_post-queue', 'notificationType_new-post-flag');
|
}
|
||||||
}
|
const results = await plugins.fireHook('filter:user.notificationTypes', {
|
||||||
if (privileges.isAdmin || privileges.isGlobalMod) {
|
types: notifications.baseTypes.slice(),
|
||||||
privilegedTypes.push('notificationType_new-user-flag');
|
privilegedTypes: privilegedTypes,
|
||||||
}
|
});
|
||||||
plugins.fireHook('filter:user.notificationTypes', {
|
|
||||||
types: notifications.baseTypes.slice(),
|
|
||||||
privilegedTypes: privilegedTypes,
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
function modifyType(type) {
|
|
||||||
var setting = userData.settings[type];
|
|
||||||
|
|
||||||
return {
|
function modifyType(type) {
|
||||||
name: type,
|
const setting = userData.settings[type];
|
||||||
label: '[[notifications:' + type + ']]',
|
return {
|
||||||
none: setting === 'none',
|
name: type,
|
||||||
notification: setting === 'notification',
|
label: '[[notifications:' + type + ']]',
|
||||||
email: setting === 'email',
|
none: setting === 'none',
|
||||||
notificationemail: setting === 'notificationemail',
|
notification: setting === 'notification',
|
||||||
};
|
email: setting === 'email',
|
||||||
}
|
notificationemail: setting === 'notificationemail',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (meta.config.disableChat) {
|
if (meta.config.disableChat) {
|
||||||
results.types = results.types.filter(type => type !== 'notificationType_new-chat');
|
results.types = results.types.filter(type => type !== 'notificationType_new-chat');
|
||||||
}
|
}
|
||||||
|
|
||||||
var notificationSettings = results.types.map(modifyType).concat(results.privilegedTypes.map(modifyType));
|
return results.types.map(modifyType).concat(results.privilegedTypes.map(modifyType));
|
||||||
next(null, notificationSettings);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHomePageRoutes(userData, callback) {
|
async function getHomePageRoutes(userData) {
|
||||||
async.waterfall([
|
let cids = await categories.getAllCidsFromSet('cid:0:children');
|
||||||
function (next) {
|
cids = await privileges.categories.filterCids('find', cids, userData.uid);
|
||||||
db.getSortedSetRange('cid:0:children', 0, -1, next);
|
let categoryData = await categories.getCategoriesFields(cids, ['name', 'slug']);
|
||||||
|
|
||||||
|
categoryData = categoryData.map(function (category) {
|
||||||
|
return {
|
||||||
|
route: 'category/' + category.slug,
|
||||||
|
name: 'Category: ' + category.name,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await plugins.fireHook('filter:homepage.get', { routes: [
|
||||||
|
{
|
||||||
|
route: 'categories',
|
||||||
|
name: 'Categories',
|
||||||
},
|
},
|
||||||
function (cids, next) {
|
{
|
||||||
privileges.categories.filterCids('find', cids, 0, next);
|
route: 'unread',
|
||||||
|
name: 'Unread',
|
||||||
},
|
},
|
||||||
function (cids, next) {
|
{
|
||||||
categories.getCategoriesFields(cids, ['name', 'slug'], next);
|
route: 'recent',
|
||||||
|
name: 'Recent',
|
||||||
},
|
},
|
||||||
function (categoryData, next) {
|
{
|
||||||
categoryData = categoryData.map(function (category) {
|
route: 'top',
|
||||||
return {
|
name: 'Top',
|
||||||
route: 'category/' + category.slug,
|
|
||||||
name: 'Category: ' + category.name,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
categoryData = categoryData || [];
|
|
||||||
|
|
||||||
plugins.fireHook('filter:homepage.get', { routes: [
|
|
||||||
{
|
|
||||||
route: 'categories',
|
|
||||||
name: 'Categories',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
route: 'unread',
|
|
||||||
name: 'Unread',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
route: 'recent',
|
|
||||||
name: 'Recent',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
route: 'top',
|
|
||||||
name: 'Top',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
route: 'popular',
|
|
||||||
name: 'Popular',
|
|
||||||
},
|
|
||||||
].concat(categoryData, [
|
|
||||||
{
|
|
||||||
route: 'custom',
|
|
||||||
name: 'Custom',
|
|
||||||
},
|
|
||||||
]) }, next);
|
|
||||||
},
|
},
|
||||||
function (data, next) {
|
{
|
||||||
// Set selected for each route
|
route: 'popular',
|
||||||
var customIdx;
|
name: 'Popular',
|
||||||
var hasSelected = false;
|
},
|
||||||
data.routes = data.routes.map(function (route, idx) {
|
].concat(categoryData, [
|
||||||
if (route.route === userData.settings.homePageRoute) {
|
{
|
||||||
route.selected = true;
|
route: 'custom',
|
||||||
hasSelected = true;
|
name: 'Custom',
|
||||||
} else {
|
},
|
||||||
route.selected = false;
|
]) });
|
||||||
}
|
|
||||||
|
// Set selected for each route
|
||||||
if (route.route === 'custom') {
|
var customIdx;
|
||||||
customIdx = idx;
|
var hasSelected = false;
|
||||||
}
|
data.routes = data.routes.map(function (route, idx) {
|
||||||
|
if (route.route === userData.settings.homePageRoute) {
|
||||||
return route;
|
route.selected = true;
|
||||||
});
|
hasSelected = true;
|
||||||
|
} else {
|
||||||
|
route.selected = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasSelected && customIdx && userData.settings.homePageRoute !== 'none') {
|
if (route.route === 'custom') {
|
||||||
data.routes[customIdx].selected = true;
|
customIdx = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
next(null, data.routes);
|
return route;
|
||||||
},
|
});
|
||||||
], callback);
|
|
||||||
|
if (!hasSelected && customIdx && userData.settings.homePageRoute !== 'none') {
|
||||||
|
data.routes[customIdx].selected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.routes;
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,40 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const nconf = require('nconf');
|
||||||
var async = require('async');
|
|
||||||
var nconf = require('nconf');
|
const db = require('../../database');
|
||||||
|
const helpers = require('../helpers');
|
||||||
var db = require('../../database');
|
const meta = require('../../meta');
|
||||||
var helpers = require('../helpers');
|
const pagination = require('../../pagination');
|
||||||
var meta = require('../../meta');
|
const accountHelpers = require('./helpers');
|
||||||
var pagination = require('../../pagination');
|
|
||||||
var accountHelpers = require('./helpers');
|
const uploadsController = module.exports;
|
||||||
|
|
||||||
var uploadsController = module.exports;
|
uploadsController.get = async function (req, res, next) {
|
||||||
|
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||||
uploadsController.get = function (req, res, callback) {
|
if (!userData) {
|
||||||
var userData;
|
return next();
|
||||||
|
}
|
||||||
var page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
|
||||||
var itemsPerPage = 25;
|
const page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
||||||
|
const itemsPerPage = 25;
|
||||||
async.waterfall([
|
const start = (page - 1) * itemsPerPage;
|
||||||
function (next) {
|
const stop = start + itemsPerPage - 1;
|
||||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
const [itemCount, uploadNames] = await Promise.all([
|
||||||
},
|
db.sortedSetCard('uid:' + userData.uid + ':uploads'),
|
||||||
function (_userData, next) {
|
db.getSortedSetRevRange('uid:' + userData.uid + ':uploads', start, stop),
|
||||||
userData = _userData;
|
]);
|
||||||
if (!userData) {
|
|
||||||
return callback();
|
userData.uploads = uploadNames.map(function (uploadName) {
|
||||||
}
|
return {
|
||||||
|
name: uploadName,
|
||||||
var start = (page - 1) * itemsPerPage;
|
url: nconf.get('upload_url') + uploadName,
|
||||||
var stop = start + itemsPerPage - 1;
|
};
|
||||||
async.parallel({
|
});
|
||||||
itemCount: function (next) {
|
const pageCount = Math.ceil(itemCount / itemsPerPage);
|
||||||
db.sortedSetCard('uid:' + userData.uid + ':uploads', next);
|
userData.pagination = pagination.create(page, pageCount, req.query);
|
||||||
},
|
userData.privateUploads = meta.config.privateUploads === 1;
|
||||||
uploadNames: function (next) {
|
userData.title = '[[pages:account/uploads, ' + userData.username + ']]';
|
||||||
db.getSortedSetRevRange('uid:' + userData.uid + ':uploads', start, stop, next);
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:uploads]]' }]);
|
||||||
},
|
res.render('account/uploads', userData);
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results) {
|
|
||||||
userData.uploads = results.uploadNames.map(function (uploadName) {
|
|
||||||
return {
|
|
||||||
name: uploadName,
|
|
||||||
url: nconf.get('upload_url') + uploadName,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
|
|
||||||
userData.pagination = pagination.create(page, pageCount, req.query);
|
|
||||||
userData.privateUploads = meta.config.privateUploads === 1;
|
|
||||||
userData.title = '[[pages:account/uploads, ' + userData.username + ']]';
|
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:uploads]]' }]);
|
|
||||||
res.render('account/uploads', userData);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue