return user settings in api

v1.18.x
barisusakli 10 years ago
parent 27bf1c1b2e
commit 0083d4ff1c

@ -61,31 +61,6 @@ define('forum/account/settings', ['forum/account/header'], function(header) {
return false; return false;
}); });
socket.emit('user.getSettings', {uid: ajaxify.variables.get('theirid')}, function(err, settings) {
var inputs = $('.account').find('input, textarea, select');
inputs.each(function(index, input) {
input = $(input);
var setting = input.attr('data-property');
if (setting) {
if (input.is('select')) {
input.val(settings[setting] || '');
return;
}
switch (input.attr('type')) {
case 'text' :
case 'textarea' :
input.val(settings[setting]);
break;
case 'checkbox' :
input.prop('checked', !!settings[setting]);
break;
}
}
});
});
}; };
return AccountSettings; return AccountSettings;

@ -375,18 +375,19 @@ accountsController.accountEdit = function(req, res, next) {
}; };
accountsController.accountSettings = function(req, res, next) { accountsController.accountSettings = function(req, res, next) {
accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) { var userData;
if (err) { async.waterfall([
return next(err); function(next) {
} accountsController.getBaseUser(req.params.userslug, req.uid, next);
},
function(_userData, next) {
userData = _userData;
if (!userData) { if (!userData) {
return helpers.notFound(req, res); return helpers.notFound(req, res);
} }
async.parallel({ async.parallel({
settings: function(next) { settings: function(next) {
plugins.fireHook('filter:user.settings', [], next); user.getSettings(userData.uid, next);
}, },
userGroups: function(next) { userGroups: function(next) {
groups.getUserGroups([userData.uid], next); groups.getUserGroups([userData.uid], next);
@ -394,19 +395,39 @@ accountsController.accountSettings = function(req, res, next) {
languages: function(next) { languages: function(next) {
languages.list(next); languages.list(next);
} }
}, function(err, results) { }, next);
},
function(results, next) {
userData.languages = results.languages;
userData.userGroups = results.userGroups[0];
plugins.fireHook('filter:user.settings', {settings: results.settings, uid: req.uid}, next);
},
function(data, next) {
userData.settings = data.settings;
userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
next();
}
], function(err) {
if (err) { if (err) {
return next(err); return next(err);
} }
userData.settings = results.settings; userData.dailyDigestFreqOptions = [
userData.languages = results.languages; {value: 'off', name: '[[user:digest_off]]', selected: 'off' === userData.settings.dailyDigestFreq},
userData.userGroups = results.userGroups[0]; {value: 'day', name: '[[user:digest_daily]]', selected: 'day' === userData.settings.dailyDigestFreq},
{value: 'week', name: '[[user:digest_weekly]]', selected: 'week' === userData.settings.dailyDigestFreq},
{value: 'month', name: '[[user:digest_monthly]]', selected: 'month' === userData.settings.dailyDigestFreq}
];
userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1; userData.userGroups.forEach(function(group) {
group.selected = group.name === userData.settings.groupTitle;
});
res.render('account/settings', userData); userData.languages.forEach(function(language) {
language.selected = language.code === userData.settings.language;
}); });
res.render('account/settings', userData);
}); });
}; };

@ -340,26 +340,6 @@ function toggleFollow(method, uid, theiruid, callback) {
}); });
} }
SocketUser.getSettings = function(socket, data, callback) {
if (socket.uid) {
if (socket.uid === parseInt(data.uid, 10)) {
return user.getSettings(socket.uid, callback);
}
user.isAdministrator(socket.uid, function(err, isAdmin) {
if (err) {
return callback(err);
}
if (!isAdmin) {
return callback(new Error('[[error:no-privileges]]'));
}
user.getSettings(data.uid, callback);
});
}
};
SocketUser.saveSettings = function(socket, data, callback) { SocketUser.saveSettings = function(socket, data, callback) {
if (!socket.uid || !data) { if (!socket.uid || !data) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));

Loading…
Cancel
Save