Merge branch 'master' of github.com:psychobunny/NodeBB

v1.18.x
Julian Lam 12 years ago
commit aab149aecf

@ -4,6 +4,13 @@ var config = {
// "base_url" is expected to be a publically accessible URL to your NodeBB instance (Default base_url: 'http://localhost', port: '4567') // "base_url" is expected to be a publically accessible URL to your NodeBB instance (Default base_url: 'http://localhost', port: '4567')
"base_url": "http://localhost", "base_url": "http://localhost",
// public url for uploaded files
"upload_url": "http://dev.domain.com/uploads/",
// relative path for uploads
"upload_path": "/uploads/",
"use_port": true, "use_port": true,
"port": 4567, "port": 4567,

@ -19,13 +19,13 @@
<div id="gravatar-box"> <div id="gravatar-box">
<img id="user-gravatar-picture" src="" class="img-polaroid user-profile-picture"> <img id="user-gravatar-picture" src="" class="img-polaroid user-profile-picture">
<span class="user-picture-label">Gravatar</span> <span class="user-picture-label">Gravatar</span>
<i class='icon-ok'></i> <i class='icon-ok icon-2x'></i>
</div> </div>
<div id="uploaded-box"> <div id="uploaded-box">
<img id="user-uploaded-picture" src="" class="img-polaroid user-profile-picture"> <img id="user-uploaded-picture" src="" class="img-polaroid user-profile-picture">
<span class="user-picture-label">Uploaded picture</span> <span class="user-picture-label">Uploaded picture</span>
<i class='icon-ok'></i> <i class='icon-ok icon-2x'></i>
</div> </div>
<a id="uploadPictureBtn" href="#">Upload new picture</a> <a id="uploadPictureBtn" href="#">Upload new picture</a>
@ -50,7 +50,9 @@
<input id="userPhotoInput" type="file" name="userPhoto" > <input id="userPhotoInput" type="file" name="userPhoto" >
</form> </form>
<span id="status" /> <div id="alert-status" class="alert hide"></div>
<div id="alert-success" class="alert alert-success hide"></div>
<div id="alert-error" class="alert alert-error hide"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -139,15 +141,20 @@ $(document).ready(function() {
$('#uploadForm').submit(function() { $('#uploadForm').submit(function() {
status('uploading the file ...'); status('uploading the file ...');
if(!$('#userPhotoInput').val()) {
error('select an image to upload!');
return false;
}
$(this).ajaxSubmit({ $(this).ajaxSubmit({
error: function(xhr) { error: function(xhr) {
status('Error: ' + xhr.status); error('Error: ' + xhr.status);
}, },
success: function(response) { success: function(response) {
if(response.error) { if(response.error) {
status('Opps, something bad happened'); error(response.error);
return; return;
} }
@ -158,40 +165,38 @@ $(document).ready(function() {
$('#user-data-uploadedpicture').html(imageUrlOnServer); $('#user-data-uploadedpicture').html(imageUrlOnServer);
setTimeout(function() {
hideAlerts();
$('#upload-picture-modal').modal('hide'); $('#upload-picture-modal').modal('hide');
}, 750);
socket.emit('api:updateHeader', { fields: ['username', 'picture'] }); socket.emit('api:updateHeader', { fields: ['username', 'picture'] });
status(''); success('File uploaded successfully!');
} }
}); });
return false; return false;
}); });
function status(message) { function hideAlerts() {
$('#status').text(message); $('#alert-status').hide();
$('#alert-success').hide();
$('#alert-error').hide();
} }
});
(function() { function status(message) {
hideAlerts();
function submitUserData() { $('#alert-status').text(message).show();
var userData = { }
uid:$('#inputUID').val(),
email:$('#inputEmail').val(),
fullname:$('#inputFullname').val(),
website:$('#inputWebsite').val(),
birthday:$('#inputBirthday').val(),
location:$('#inputLocation').val()
};
$.post('/edituser',
userData,
function(data) {
function success(message) {
hideAlerts();
$('#alert-success').text(message).show();
} }
);
function error(message) {
hideAlerts();
$('#alert-error').text(message).show();
} }
function changeUserPicture(type) { function changeUserPicture(type) {
@ -208,17 +213,26 @@ $(document).ready(function() {
); );
} }
$(document).ready(function(){
var selectedImageType = ''; var selectedImageType = '';
$('#submitBtn').on('click',function(){ $('#submitBtn').on('click',function(){
submitUserData(); var userData = {
uid:$('#inputUID').val(),
email:$('#inputEmail').val(),
fullname:$('#inputFullname').val(),
website:$('#inputWebsite').val(),
birthday:$('#inputBirthday').val(),
location:$('#inputLocation').val()
};
}); $.post('/edituser',
userData,
function(data) {
}
);
});
function updateImages() { function updateImages() {
@ -226,15 +240,19 @@ $(document).ready(function() {
var gravatarPicture = $('#user-data-gravatarpicture').html(); var gravatarPicture = $('#user-data-gravatarpicture').html();
var uploadedPicture = $('#user-data-uploadedpicture').html(); var uploadedPicture = $('#user-data-uploadedpicture').html();
if(gravatarPicture) if(gravatarPicture) {
$('#user-gravatar-picture').attr('src', gravatarPicture); $('#user-gravatar-picture').attr('src', gravatarPicture);
$('#gravatar-box').show();
}
else else
$('#user-gravatar-picture').addClass('hide'); $('#gravatar-box').hide();
if(uploadedPicture) if(uploadedPicture) {
$('#user-uploaded-picture').attr('src', uploadedPicture); $('#user-uploaded-picture').attr('src', uploadedPicture);
$('#uploaded-box').show();
}
else else
$('#user-uploaded-picture').addClass('hide'); $('#uploaded-box').hide();
if(currentPicture == gravatarPicture) if(currentPicture == gravatarPicture)
@ -292,6 +310,7 @@ $(document).ready(function() {
$('#change-picture-modal').modal('hide'); $('#change-picture-modal').modal('hide');
$('#upload-picture-modal').modal('show'); $('#upload-picture-modal').modal('show');
hideAlerts();
$('#pictureUploadSubmitBtn').on('click', function() { $('#pictureUploadSubmitBtn').on('click', function() {
$('#uploadForm').submit(); $('#uploadForm').submit();
@ -300,6 +319,6 @@ $(document).ready(function() {
return false; return false;
}); });
});
}()); });
</script> </script>

@ -11,11 +11,11 @@
<a href="/users/{users.username}">{users.username}</a> <a href="/users/{users.username}">{users.username}</a>
<br/> <br/>
<div title="reputation"> <div title="reputation">
<span id='reputation'>{users.reputation}</span> <span class='reputation'>{users.reputation}</span>
<i class='icon-star'></i> <i class='icon-star'></i>
</div> </div>
<div title="post count"> <div title="post count">
<span id='postcount'>{users.postcount}</span> <span class='postcount'>{users.postcount}</span>
<i class='icon-pencil'></i> <i class='icon-pencil'></i>
</div> </div>
@ -32,11 +32,14 @@
} }
$(document).ready(function() { $(document).ready(function() {
var rep = $('#reputation');
rep.html(addCommas(rep.html()));
var postcount = $('#postcount'); $('.reputation').each(function(index, element) {
postcount.html(addCommas(postcount.html())); $(element).html(addCommas($(element).html()));
})
$('.postcount').each(function(index, element) {
$(element).html(addCommas($(element).html()));
})
}); });

@ -227,6 +227,13 @@ var express = require('express'),
if(!req.user) if(!req.user)
return res.redirect('/403'); return res.redirect('/403');
if(req.files.userPhoto.size > 131072) {
res.send({
error: 'Images must be smaller than 128kb!'
});
return;
}
user.getUserField(req.user.uid, 'uploadedpicture', function(uploadedpicture) { user.getUserField(req.user.uid, 'uploadedpicture', function(uploadedpicture) {
var index = uploadedpicture.lastIndexOf('/'); var index = uploadedpicture.lastIndexOf('/');
@ -248,20 +255,29 @@ var express = require('express'),
}); });
function uploadUserPicture(uid, filename, tempPath, res) { function uploadUserPicture(uid, filename, tempPath, res) {
var uploadPath = config['upload_path'] + uid + '-' + filename;
if(!filename){
res.send({
error: 'Error uploading file! Error : Invalid file name!'
});
return;
}
filename = uid + '-' + filename
var uploadPath = config.upload_path + filename;
fs.rename( fs.rename(
tempPath, tempPath,
global.configuration['ROOT_DIRECTORY']+ uploadPath, global.configuration['ROOT_DIRECTORY'] + uploadPath,
function(error) { function(error) {
if(error) { if(error) {
res.send({ res.send({
error: 'Ah crap! Something bad happened' error: 'Error uploading file!'
}); });
return; return;
} }
var imageUrl = config.base_url + config.install_path + uploadPath; var imageUrl = config.upload_url + filename;
res.send({ res.send({
path: imageUrl path: imageUrl
@ -272,7 +288,6 @@ var express = require('express'),
} }
); );
} }

Loading…
Cancel
Save