mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-30 09:56:13 +02:00
Merge branch 'master' into edit_delete
This commit is contained in:
@@ -5,6 +5,10 @@ var RDB = require('./redis.js'),
|
||||
topics = require('./topics.js'),
|
||||
config = require('../config.js');
|
||||
|
||||
marked.setOptions({
|
||||
breaks: true
|
||||
});
|
||||
|
||||
(function(Posts) {
|
||||
|
||||
Posts.get = function(callback, tid, current_user, start, end) {
|
||||
@@ -36,7 +40,7 @@ var RDB = require('./redis.js'),
|
||||
'user_rep' : user_data[uid].reputation || 0,
|
||||
'gravatar' : user_data[uid].picture,
|
||||
'fav_star_class' : vote_data[pid] ? 'icon-star' : 'icon-star-empty',
|
||||
'display_moderator_tools' : uid == current_user ? 'show' : 'none',
|
||||
'display_moderator_tools': (uid == current_user || viewer_data.reputation >= config.privilege_thresholds.manage_content) ? 'show' : 'none',
|
||||
'edited-class': post_data.editor[i] !== null ? '' : 'none',
|
||||
'editor': post_data.editor[i] !== null ? user_data[post_data.editor[i]].username : '',
|
||||
'relativeEditTime': post_data.editTime !== null ? utils.relativeTime(post_data.editTime[i]) : ''
|
||||
|
||||
@@ -36,7 +36,6 @@ var config = require('../config.js'),
|
||||
|
||||
// a function I feel should be built in user not sure how baris is tackling this so oppa chicken wrapper here
|
||||
User.getMultipleUserFields = function(uids, fields, callback) {
|
||||
console.log(uids);
|
||||
var uuids = uids.filter(function(value, index, self) {
|
||||
return self.indexOf(value) === index;
|
||||
});
|
||||
@@ -253,6 +252,8 @@ var config = require('../config.js'),
|
||||
|
||||
User.hashPassword(password, function(hash) {
|
||||
|
||||
var gravatar = User.createGravatarURLFromEmail(email);
|
||||
|
||||
RDB.hmset('user:'+uid, {
|
||||
'username' : username,
|
||||
'fullname': '',
|
||||
@@ -262,7 +263,9 @@ var config = require('../config.js'),
|
||||
'email' : email,
|
||||
'joindate' : new Date().getTime(),
|
||||
'password' : hash,
|
||||
'picture' : User.createGravatarURLFromEmail(email),
|
||||
'picture': gravatar,
|
||||
'gravatarpicture' : gravatar,
|
||||
'uploadedpicture': '',
|
||||
'reputation': 0,
|
||||
'postcount': 0
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ var express = require('express'),
|
||||
|
||||
user = require('./user.js'),
|
||||
utils = require('./utils.js'),
|
||||
fs = require('fs'),
|
||||
admin = require('./routes/admin.js'),
|
||||
auth = require('./routes/authentication.js');
|
||||
|
||||
@@ -199,6 +200,82 @@ var express = require('express'),
|
||||
|
||||
// TODO move user related logic into another file vvvvvvvvvvvvvvvvvvvv
|
||||
|
||||
app.post('/pictureupload', function(req, res) {
|
||||
|
||||
if(!req.user)
|
||||
return res.redirect('/403');
|
||||
|
||||
user.getUserField(req.user.uid, 'uploadedpicture', function(uploadedpicture) {
|
||||
|
||||
var index = uploadedpicture.lastIndexOf('/');
|
||||
var filename = uploadedpicture.substr(index+1);
|
||||
|
||||
var absolutePath = global.configuration['ROOT_DIRECTORY'] + config.upload_path + filename;
|
||||
|
||||
fs.unlink(absolutePath, function(err) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
uploadUserPicture(req.user.uid, req.files.userPhoto.name, req.files.userPhoto.path, res);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function uploadUserPicture(uid, filename, tempPath, res) {
|
||||
var uploadPath = config['upload_path'] + uid + '-' + filename;
|
||||
|
||||
fs.rename(
|
||||
tempPath,
|
||||
global.configuration['ROOT_DIRECTORY']+ uploadPath,
|
||||
function(error) {
|
||||
if(error) {
|
||||
res.send({
|
||||
error: 'Ah crap! Something bad happened'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var imageUrl = config.base_url + config.install_path + uploadPath;
|
||||
|
||||
res.send({
|
||||
path: imageUrl
|
||||
});
|
||||
|
||||
user.setUserField(uid, 'uploadedpicture', imageUrl);
|
||||
user.setUserField(uid, 'picture', imageUrl);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
app.post('/changeuserpicture', function(req, res){
|
||||
if(!req.user)
|
||||
return res.redirect('/403');
|
||||
|
||||
if(req.user.uid != req.body.uid)
|
||||
return res.redirect('/');
|
||||
|
||||
var type = req.body.type;
|
||||
if(type == 'gravatar') {
|
||||
user.getUserField(req.user.uid, 'gravatarpicture', function(gravatar){
|
||||
user.setUserField(req.user.uid, 'picture', gravatar);
|
||||
});
|
||||
}
|
||||
else if(type == 'uploaded') {
|
||||
user.getUserField(req.user.uid, 'uploadedpicture', function(uploadedpicture){
|
||||
user.setUserField(req.user.uid, 'picture', uploadedpicture);
|
||||
});
|
||||
}
|
||||
res.send({});
|
||||
});
|
||||
|
||||
|
||||
app.post('/edituser', function(req, res){
|
||||
|
||||
if(!req.user)
|
||||
|
||||
Reference in New Issue
Block a user