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": "http://localhost",
// public url for uploaded files
"upload_url": "http://dev.domain.com/uploads/",
// relative path for uploads
"upload_path": "/uploads/",
"use_port": true,
"port": 4567,

@ -19,13 +19,13 @@
<div id="gravatar-box">
<img id="user-gravatar-picture" src="" class="img-polaroid user-profile-picture">
<span class="user-picture-label">Gravatar</span>
<i class='icon-ok'></i>
<i class='icon-ok icon-2x'></i>
</div>
<div id="uploaded-box">
<img id="user-uploaded-picture" src="" class="img-polaroid user-profile-picture">
<span class="user-picture-label">Uploaded picture</span>
<i class='icon-ok'></i>
<i class='icon-ok icon-2x'></i>
</div>
<a id="uploadPictureBtn" href="#">Upload new picture</a>
@ -50,7 +50,9 @@
<input id="userPhotoInput" type="file" name="userPhoto" >
</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 class="modal-footer">
@ -138,16 +140,21 @@ $(document).ready(function() {
$('#uploadForm').submit(function() {
status('uploading the file ...');
if(!$('#userPhotoInput').val()) {
error('select an image to upload!');
return false;
}
$(this).ajaxSubmit({
error: function(xhr) {
status('Error: ' + xhr.status);
error('Error: ' + xhr.status);
},
success: function(response) {
if(response.error) {
status('Opps, something bad happened');
error(response.error);
return;
}
@ -158,41 +165,39 @@ $(document).ready(function() {
$('#user-data-uploadedpicture').html(imageUrlOnServer);
$('#upload-picture-modal').modal('hide');
setTimeout(function() {
hideAlerts();
$('#upload-picture-modal').modal('hide');
}, 750);
socket.emit('api:updateHeader', { fields: ['username', 'picture'] });
status('');
success('File uploaded successfully!');
}
});
return false;
});
function hideAlerts() {
$('#alert-status').hide();
$('#alert-success').hide();
$('#alert-error').hide();
}
function status(message) {
$('#status').text(message);
hideAlerts();
$('#alert-status').text(message).show();
}
function success(message) {
hideAlerts();
$('#alert-success').text(message).show();
}
function error(message) {
hideAlerts();
$('#alert-error').text(message).show();
}
});
(function() {
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 changeUserPicture(type) {
var userData = {
@ -207,99 +212,113 @@ $(document).ready(function() {
}
);
}
$(document).ready(function(){
var selectedImageType = '';
$('#submitBtn').on('click',function(){
var selectedImageType = '';
$('#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() {
var currentPicture = $('#user-current-picture').attr('src');
var gravatarPicture = $('#user-data-gravatarpicture').html();
var uploadedPicture = $('#user-data-uploadedpicture').html();
}
);
});
function updateImages() {
var currentPicture = $('#user-current-picture').attr('src');
var gravatarPicture = $('#user-data-gravatarpicture').html();
var uploadedPicture = $('#user-data-uploadedpicture').html();
if(gravatarPicture)
$('#user-gravatar-picture').attr('src', gravatarPicture);
else
$('#user-gravatar-picture').addClass('hide');
if(gravatarPicture) {
$('#user-gravatar-picture').attr('src', gravatarPicture);
$('#gravatar-box').show();
}
else
$('#gravatar-box').hide();
if(uploadedPicture)
$('#user-uploaded-picture').attr('src', uploadedPicture);
else
$('#user-uploaded-picture').addClass('hide');
if(currentPicture == gravatarPicture)
$('#gravatar-box .icon-ok').show();
else
$('#gravatar-box .icon-ok').hide();
if(currentPicture == uploadedPicture)
$('#uploaded-box .icon-ok').show();
else
$('#uploaded-box .icon-ok').hide();
if(uploadedPicture) {
$('#user-uploaded-picture').attr('src', uploadedPicture);
$('#uploaded-box').show();
}
$('#changePictureBtn').on('click', function() {
selectedImageType = '';
updateImages();
else
$('#uploaded-box').hide();
$('#change-picture-modal').modal('show');
return false;
});
$('#gravatar-box').on('click', function(){
$('#gravatar-box .icon-ok').show();
if(currentPicture == gravatarPicture)
$('#gravatar-box .icon-ok').show();
else
$('#gravatar-box .icon-ok').hide();
if(currentPicture == uploadedPicture)
$('#uploaded-box .icon-ok').show();
else
$('#uploaded-box .icon-ok').hide();
selectedImageType = 'gravatar';
});
}
$('#changePictureBtn').on('click', function() {
selectedImageType = '';
updateImages();
$('#uploaded-box').on('click', function(){
$('#gravatar-box .icon-ok').hide();
$('#uploaded-box .icon-ok').show();
selectedImageType = 'uploaded';
});
$('#change-picture-modal').modal('show');
$('#savePictureChangesBtn').on('click', function() {
$('#change-picture-modal').modal('hide');
return false;
});
$('#gravatar-box').on('click', function(){
$('#gravatar-box .icon-ok').show();
$('#uploaded-box .icon-ok').hide();
selectedImageType = 'gravatar';
});
$('#uploaded-box').on('click', function(){
$('#gravatar-box .icon-ok').hide();
$('#uploaded-box .icon-ok').show();
selectedImageType = 'uploaded';
});
$('#savePictureChangesBtn').on('click', function() {
$('#change-picture-modal').modal('hide');
if(selectedImageType) {
changeUserPicture(selectedImageType);
if(selectedImageType == 'gravatar')
$('#user-current-picture').attr('src', $('#user-data-gravatarpicture').html());
else if(selectedImageType == 'uploaded')
$('#user-current-picture').attr('src', $('#user-data-uploadedpicture').html());
}
if(selectedImageType) {
changeUserPicture(selectedImageType);
});
if(selectedImageType == 'gravatar')
$('#user-current-picture').attr('src', $('#user-data-gravatarpicture').html());
else if(selectedImageType == 'uploaded')
$('#user-current-picture').attr('src', $('#user-data-uploadedpicture').html());
}
$('#upload-picture-modal').on('hide', function() {
$('#userPhotoInput').val('');
});
});
$('#upload-picture-modal').on('hide', function() {
$('#userPhotoInput').val('');
});
$('#uploadPictureBtn').on('click', function(){
$('#change-picture-modal').modal('hide');
$('#upload-picture-modal').modal('show');
hideAlerts();
$('#uploadPictureBtn').on('click', function(){
$('#change-picture-modal').modal('hide');
$('#upload-picture-modal').modal('show');
$('#pictureUploadSubmitBtn').on('click', function() {
$('#uploadForm').submit();
});
return false;
$('#pictureUploadSubmitBtn').on('click', function() {
$('#uploadForm').submit();
});
});
}());
return false;
});
});
</script>

@ -11,11 +11,11 @@
<a href="/users/{users.username}">{users.username}</a>
<br/>
<div title="reputation">
<span id='reputation'>{users.reputation}</span>
<span class='reputation'>{users.reputation}</span>
<i class='icon-star'></i>
</div>
<div title="post count">
<span id='postcount'>{users.postcount}</span>
<span class='postcount'>{users.postcount}</span>
<i class='icon-pencil'></i>
</div>
@ -32,11 +32,14 @@
}
$(document).ready(function() {
var rep = $('#reputation');
rep.html(addCommas(rep.html()));
var postcount = $('#postcount');
postcount.html(addCommas(postcount.html()));
$('.reputation').each(function(index, element) {
$(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)
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) {
var index = uploadedpicture.lastIndexOf('/');
@ -248,20 +255,29 @@ var express = require('express'),
});
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(
tempPath,
global.configuration['ROOT_DIRECTORY']+ uploadPath,
global.configuration['ROOT_DIRECTORY'] + uploadPath,
function(error) {
if(error) {
res.send({
error: 'Ah crap! Something bad happened'
error: 'Error uploading file!'
});
return;
}
var imageUrl = config.base_url + config.install_path + uploadPath;
var imageUrl = config.upload_url + filename;
res.send({
path: imageUrl
@ -272,7 +288,6 @@ var express = require('express'),
}
);
}

Loading…
Cancel
Save