From 9749658d35c2dd2ccbf608a7327db39fb3c3564e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 29 Apr 2015 14:29:18 -0400 Subject: [PATCH] added about me field --- install/data/defaults.json | 4 ++++ public/language/en_GB/error.json | 1 + public/language/en_GB/user.json | 1 + public/src/client/account/edit.js | 26 +++++++++++++++++++------- src/controllers/accounts.js | 10 +++++++++- src/controllers/api.js | 1 + src/user/profile.js | 12 ++++++++++-- src/views/admin/settings/user.tpl | 4 ++++ 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 980e673325..9a0d6eb1ec 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -83,6 +83,10 @@ "field": "maximumSignatureLength", "value": 255 }, + { + "field": "maximumAboutMeLength", + "value": 1000 + }, { "field": "maximumProfileImageSize", "value": 256 diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index 2265e78ca1..80f38952fc 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -89,6 +89,7 @@ "uploads-are-disabled": "Uploads are disabled", "signature-too-long" : "Sorry, your signature cannot be longer than %1 characters.", + "about-me-too-long" : "Sorry, your about me cannot be longer than %1 characters.", "cant-chat-with-yourself": "You can't chat with yourself!", "chat-restricted": "This user has restricted their chat messages. They must follow you before you can chat with them", diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index b60b79f069..99f118ad5a 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -23,6 +23,7 @@ "watched": "Watched", "followers": "Followers", "following": "Following", + "aboutme": "About me", "signature": "Signature", "gravatar": "Gravatar", "birthday": "Birthday", diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js index 42dd151e6f..e7ed54cbbe 100644 --- a/public/src/client/account/edit.js +++ b/public/src/client/account/edit.js @@ -31,6 +31,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], handleEmailConfirm(); handlePasswordChange(); updateSignature(); + updateAboutMe(); updateImages(); }; @@ -43,7 +44,8 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], website: $('#inputWebsite').val(), birthday: $('#inputBirthday').val(), location: $('#inputLocation').val(), - signature: $('#inputSignature').val() + signature: $('#inputSignature').val(), + aboutme: $('#inputAboutMe').val() }; socket.emit('user.updateProfile', userData, function(err, data) { @@ -337,15 +339,25 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], $('#uploaded-box .fa-check').toggle(currentPicture === uploadedPicture); } + function getCharsLeft(el, max) { + return el.length ? '(' + el.val().length + '/' + max + ')' : ''; + } + function updateSignature() { - function getSignatureCharsLeft() { - return $('#inputSignature').length ? '(' + $('#inputSignature').val().length + '/' + config.maximumSignatureLength + ')' : ''; - } + var el = $('#inputSignature'); + $('#signatureCharCountLeft').html(getCharsLeft(el, config.maximumSignatureLength)); + + el.on('keyup change', function() { + $('#signatureCharCountLeft').html(getCharsLeft(el, config.maximumSignatureLength)); + }); + } - $('#signatureCharCountLeft').html(getSignatureCharsLeft()); + function updateAboutMe() { + var el = $('#inputAboutMe'); + $('#aboutMeCharCountLeft').html(getCharsLeft(el, config.maximumAboutMeLength)); - $('#inputSignature').on('keyup change', function(ev) { - $('#signatureCharCountLeft').html(getSignatureCharsLeft()); + el.on('keyup change', function() { + $('#aboutMeCharCountLeft').html(getCharsLeft(el, config.maximumAboutMeLength)); }); } diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 8dd8860a45..dcff0f5ad2 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -97,6 +97,7 @@ function getUserDataByUserSlug(userslug, callerUID, callback) { userData.fullname = validator.escape(userData.fullname); userData.location = validator.escape(userData.location); userData.signature = validator.escape(userData.signature); + userData.aboutme = validator.escape(userData.aboutme || ''); callback(null, userData); }); @@ -154,6 +155,13 @@ accountsController.getAccount = function(req, res, next) { }, signature: function(next) { posts.parseSignature(userData, req.uid, next); + }, + aboutme: function(next) { + if (userData.aboutme) { + plugins.fireHook('filter:parse.raw', userData.aboutme, next); + } else { + next(); + } } }, function(err, results) { if(err) { @@ -163,7 +171,7 @@ accountsController.getAccount = function(req, res, next) { userData.posts = results.posts.posts.filter(function (p) { return p && parseInt(p.deleted, 10) !== 1; }); - + userData.aboutme = results.aboutme; userData.nextStart = results.posts.nextStart; userData.isFollowing = results.isFollowing; diff --git a/src/controllers/api.js b/src/controllers/api.js index c531f6d87b..1af6e441fd 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -39,6 +39,7 @@ apiController.getConfig = function(req, res, next) { config.maximumUsernameLength = meta.config.maximumUsernameLength; config.minimumPasswordLength = meta.config.minimumPasswordLength; config.maximumSignatureLength = meta.config.maximumSignatureLength; + config.maximumAboutMeLength = meta.config.maximumAboutMeLength; config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1; config.allowGuestSearching = parseInt(meta.config.allowGuestSearching, 10) === 1; config.allowGuestHandles = parseInt(meta.config.allowGuestHandles, 10) === 1; diff --git a/src/user/profile.js b/src/user/profile.js index e8c7055d14..7265d5896b 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -16,7 +16,7 @@ var async = require('async'), module.exports = function(User) { User.updateProfile = function(uid, data, callback) { - var fields = ['username', 'email', 'fullname', 'website', 'location', 'birthday', 'signature']; + var fields = ['username', 'email', 'fullname', 'website', 'location', 'birthday', 'signature', 'aboutme']; plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, function(err, data) { if (err) { @@ -26,6 +26,14 @@ module.exports = function(User) { fields = data.fields; data = data.data; + function isAboutMeValid(next) { + if (data.aboutme !== undefined && data.aboutme.length > meta.config.maximumAboutMeLength) { + next(new Error('[[error:about-me-too-long, ' + meta.config.maximumAboutMeLength + ']]')); + } else { + next(); + } + } + function isSignatureValid(next) { if (data.signature !== undefined && data.signature.length > meta.config.maximumSignatureLength) { next(new Error('[[error:signature-too-long, ' + meta.config.maximumSignatureLength + ']]')); @@ -92,7 +100,7 @@ module.exports = function(User) { }); } - async.series([isSignatureValid, isEmailAvailable, isUsernameAvailable], function(err, results) { + async.series([isAboutMeValid, isSignatureValid, isEmailAvailable, isUsernameAvailable], function(err) { if (err) { return callback(err); } diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index 2db779fe27..c2832c530a 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -132,6 +132,10 @@ +
+ + +