|
|
|
@ -1,82 +1,82 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* globals define, ajaxify, socket, app, config, utils, translator */
|
|
|
|
|
|
|
|
|
|
define(['forum/accountheader', 'uploader'], function(header, uploader) {
|
|
|
|
|
var AccountEdit = {},
|
|
|
|
|
gravatarPicture = '',
|
|
|
|
|
uploadedPicture = '';
|
|
|
|
|
uploadedPicture = '',
|
|
|
|
|
selectedImageType = '';
|
|
|
|
|
|
|
|
|
|
AccountEdit.init = function() {
|
|
|
|
|
header.init();
|
|
|
|
|
|
|
|
|
|
gravatarPicture = ajaxify.variables.get('gravatarpicture');
|
|
|
|
|
uploadedPicture = ajaxify.variables.get('uploadedpicture');
|
|
|
|
|
|
|
|
|
|
var selectedImageType = '';
|
|
|
|
|
|
|
|
|
|
$('#submitBtn').on('click', function() {
|
|
|
|
|
header.init();
|
|
|
|
|
|
|
|
|
|
var userData = {
|
|
|
|
|
uid: $('#inputUID').val(),
|
|
|
|
|
username: $('#inputUsername').val(),
|
|
|
|
|
email: $('#inputEmail').val(),
|
|
|
|
|
fullname: $('#inputFullname').val(),
|
|
|
|
|
website: $('#inputWebsite').val(),
|
|
|
|
|
birthday: $('#inputBirthday').val(),
|
|
|
|
|
location: $('#inputLocation').val(),
|
|
|
|
|
signature: $('#inputSignature').val()
|
|
|
|
|
};
|
|
|
|
|
$('#submitBtn').on('click', updateProfile);
|
|
|
|
|
|
|
|
|
|
socket.emit('user.updateProfile', userData, function(err, data) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
handleImageChange();
|
|
|
|
|
handleImageUpload();
|
|
|
|
|
handlePasswordChange();
|
|
|
|
|
updateSignature();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
return app.alertError('There was an error updating the profile!');
|
|
|
|
|
}
|
|
|
|
|
function updateProfile() {
|
|
|
|
|
var userData = {
|
|
|
|
|
uid: $('#inputUID').val(),
|
|
|
|
|
username: $('#inputUsername').val(),
|
|
|
|
|
email: $('#inputEmail').val(),
|
|
|
|
|
fullname: $('#inputFullname').val(),
|
|
|
|
|
website: $('#inputWebsite').val(),
|
|
|
|
|
birthday: $('#inputBirthday').val(),
|
|
|
|
|
location: $('#inputLocation').val(),
|
|
|
|
|
signature: $('#inputSignature').val()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.alertSuccess('Profile has been updated successfully!');
|
|
|
|
|
if (data.picture) {
|
|
|
|
|
$('#user-current-picture').attr('src', data.picture);
|
|
|
|
|
$('#user_label img').attr('src', data.picture);
|
|
|
|
|
}
|
|
|
|
|
socket.emit('user.updateProfile', userData, function(err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.gravatarpicture) {
|
|
|
|
|
$('#user-gravatar-picture').attr('src', data.gravatarpicture);
|
|
|
|
|
gravatarPicture = data.gravatarpicture;
|
|
|
|
|
}
|
|
|
|
|
app.alertSuccess('[[user:profile_update_success]]');
|
|
|
|
|
|
|
|
|
|
if(data.userslug) {
|
|
|
|
|
var oldslug = $('.account-username-box').attr('data-userslug');
|
|
|
|
|
$('.account-username-box a').each(function(index) {
|
|
|
|
|
$(this).attr('href', $(this).attr('href').replace(oldslug, data.userslug));
|
|
|
|
|
});
|
|
|
|
|
if (data.picture) {
|
|
|
|
|
$('#user-current-picture').attr('src', data.picture);
|
|
|
|
|
$('#user_label img').attr('src', data.picture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('.account-username-box').attr('data-userslug', data.userslug);
|
|
|
|
|
if (data.gravatarpicture) {
|
|
|
|
|
$('#user-gravatar-picture').attr('src', data.gravatarpicture);
|
|
|
|
|
gravatarPicture = data.gravatarpicture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#user-profile-link').attr('href', config.relative_path + '/user/' + data.userslug);
|
|
|
|
|
$('#user-profile-link span').html(' ' + userData.username);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
if (data.userslug) {
|
|
|
|
|
var oldslug = $('.account-username-box').attr('data-userslug');
|
|
|
|
|
$('.account-username-box a').each(function(index) {
|
|
|
|
|
$(this).attr('href', $(this).attr('href').replace(oldslug, data.userslug));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.account-username-box').attr('data-userslug', data.userslug);
|
|
|
|
|
|
|
|
|
|
function getSignatureCharsLeft() {
|
|
|
|
|
if($('#inputSignature').length) {
|
|
|
|
|
return '(' + $('#inputSignature').val().length + '/' + config.maximumSignatureLength + ')';
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
$('#user-profile-link').attr('href', config.relative_path + '/user/' + data.userslug);
|
|
|
|
|
$('#user-profile-link span').html(' ' + userData.username);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#signatureCharCountLeft').html(getSignatureCharsLeft());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#inputSignature').on('keyup change', function(ev) {
|
|
|
|
|
$('#signatureCharCountLeft').html(getSignatureCharsLeft());
|
|
|
|
|
});
|
|
|
|
|
function handleImageChange() {
|
|
|
|
|
function selectImageType(type) {
|
|
|
|
|
$('#gravatar-box .fa-check').toggle(type === 'gravatar');
|
|
|
|
|
$('#uploaded-box .fa-check').toggle(type === 'uploaded');
|
|
|
|
|
selectedImageType = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#changePictureBtn').on('click', function() {
|
|
|
|
|
selectedImageType = '';
|
|
|
|
|
AccountEdit.updateImages();
|
|
|
|
|
updateImages();
|
|
|
|
|
|
|
|
|
|
$('#change-picture-modal').modal('show');
|
|
|
|
|
$('#change-picture-modal').removeClass('hide');
|
|
|
|
@ -85,31 +85,29 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#gravatar-box').on('click', function() {
|
|
|
|
|
$('#gravatar-box .fa-check').show();
|
|
|
|
|
$('#uploaded-box .fa-check').hide();
|
|
|
|
|
selectedImageType = 'gravatar';
|
|
|
|
|
selectImageType('gravatar');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#uploaded-box').on('click', function() {
|
|
|
|
|
$('#gravatar-box .fa-check').hide();
|
|
|
|
|
$('#uploaded-box .fa-check').show();
|
|
|
|
|
selectedImageType = 'uploaded';
|
|
|
|
|
selectImageType('uploaded');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#savePictureChangesBtn').on('click', function() {
|
|
|
|
|
$('#change-picture-modal').modal('hide');
|
|
|
|
|
|
|
|
|
|
if (selectedImageType) {
|
|
|
|
|
AccountEdit.changeUserPicture(selectedImageType);
|
|
|
|
|
changeUserPicture(selectedImageType);
|
|
|
|
|
|
|
|
|
|
if (selectedImageType == 'gravatar')
|
|
|
|
|
if (selectedImageType === 'gravatar') {
|
|
|
|
|
$('#user-current-picture').attr('src', gravatarPicture);
|
|
|
|
|
else if (selectedImageType == 'uploaded')
|
|
|
|
|
} else if (selectedImageType === 'uploaded') {
|
|
|
|
|
$('#user-current-picture').attr('src', uploadedPicture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleImageUpload() {
|
|
|
|
|
$('#upload-picture-modal').on('hide', function() {
|
|
|
|
|
$('#userPhotoInput').val('');
|
|
|
|
|
});
|
|
|
|
@ -117,7 +115,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
|
|
|
|
|
$('#uploadPictureBtn').on('click', function() {
|
|
|
|
|
|
|
|
|
|
$('#change-picture-modal').modal('hide');
|
|
|
|
|
uploader.open(RELATIVE_PATH + '/user/uploadpicture', {uid: ajaxify.variables.get('theirid')}, config.maximumProfileImageSize, function(imageUrlOnServer) {
|
|
|
|
|
uploader.open(config.relative_path + '/user/uploadpicture', {uid: ajaxify.variables.get('theirid')}, config.maximumProfileImageSize, function(imageUrlOnServer) {
|
|
|
|
|
imageUrlOnServer = imageUrlOnServer + '?' + new Date().getTime();
|
|
|
|
|
|
|
|
|
|
$('#user-current-picture').attr('src', imageUrlOnServer);
|
|
|
|
@ -130,137 +128,129 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
|
|
|
|
|
}, app.updateHeader);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showError(element, msg) {
|
|
|
|
|
translator.translate(msg, function(msg) {
|
|
|
|
|
element.html(msg);
|
|
|
|
|
element.parent()
|
|
|
|
|
.removeClass('alert-success')
|
|
|
|
|
.addClass('alert-danger');
|
|
|
|
|
element.show();
|
|
|
|
|
validationError = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSuccess(element, msg) {
|
|
|
|
|
translator.translate(msg, function(msg) {
|
|
|
|
|
element.html(msg);
|
|
|
|
|
element.parent()
|
|
|
|
|
.removeClass('alert-danger')
|
|
|
|
|
.addClass('alert-success');
|
|
|
|
|
element.show();
|
|
|
|
|
});
|
|
|
|
|
function handlePasswordChange() {
|
|
|
|
|
var currentPassword = $('#inputCurrentPassword');
|
|
|
|
|
var password_notify = $('#password-notify');
|
|
|
|
|
var password_confirm_notify = $('#password-confirm-notify');
|
|
|
|
|
var password = $('#inputNewPassword');
|
|
|
|
|
var password_confirm = $('#inputNewPasswordAgain');
|
|
|
|
|
var passwordvalid = false;
|
|
|
|
|
var passwordsmatch = false;
|
|
|
|
|
var successIcon = '<i class="fa fa-check"></i>';
|
|
|
|
|
|
|
|
|
|
function onPasswordChanged() {
|
|
|
|
|
passwordvalid = utils.isPasswordValid(password.val());
|
|
|
|
|
if (password.val().length < config.minimumPasswordLength) {
|
|
|
|
|
showError(password_notify, '[[user:change_password_error_length]]');
|
|
|
|
|
} else if (!passwordvalid) {
|
|
|
|
|
showError(password_notify, '[[user:change_password_error]]');
|
|
|
|
|
} else {
|
|
|
|
|
showSuccess(password_notify, successIcon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(function handlePasswordChange() {
|
|
|
|
|
var currentPassword = $('#inputCurrentPassword');
|
|
|
|
|
var password_notify = $('#password-notify');
|
|
|
|
|
var password_confirm_notify = $('#password-confirm-notify');
|
|
|
|
|
var password = $('#inputNewPassword');
|
|
|
|
|
var password_confirm = $('#inputNewPasswordAgain');
|
|
|
|
|
var passwordvalid = false;
|
|
|
|
|
var passwordsmatch = false;
|
|
|
|
|
var successIcon = '<i class="fa fa-check"></i>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onPasswordChanged() {
|
|
|
|
|
passwordvalid = utils.isPasswordValid(password.val());
|
|
|
|
|
if (password.val().length < config.minimumPasswordLength) {
|
|
|
|
|
showError(password_notify, '[[user:change_password_error_length]]');
|
|
|
|
|
} else if (!passwordvalid) {
|
|
|
|
|
showError(password_notify, '[[user:change_password_error]]');
|
|
|
|
|
function onPasswordConfirmChanged() {
|
|
|
|
|
if(password.val()) {
|
|
|
|
|
if (password.val() !== password_confirm.val()) {
|
|
|
|
|
showError(password_confirm_notify, '[[user:change_password_error_match]]');
|
|
|
|
|
passwordsmatch = false;
|
|
|
|
|
} else {
|
|
|
|
|
showSuccess(password_notify, successIcon);
|
|
|
|
|
showSuccess(password_confirm_notify, successIcon);
|
|
|
|
|
passwordsmatch = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPasswordConfirmChanged() {
|
|
|
|
|
if(password.val()) {
|
|
|
|
|
if (password.val() !== password_confirm.val()) {
|
|
|
|
|
showError(password_confirm_notify, '[[user:change_password_error_match]]')
|
|
|
|
|
passwordsmatch = false;
|
|
|
|
|
} else {
|
|
|
|
|
showSuccess(password_confirm_notify, successIcon);
|
|
|
|
|
passwordsmatch = true;
|
|
|
|
|
password.on('blur', onPasswordChanged);
|
|
|
|
|
password_confirm.on('blur', onPasswordConfirmChanged);
|
|
|
|
|
|
|
|
|
|
$('#changePasswordBtn').on('click', function() {
|
|
|
|
|
if ((passwordvalid && passwordsmatch) || app.isAdmin) {
|
|
|
|
|
socket.emit('user.changePassword', {
|
|
|
|
|
'currentPassword': currentPassword.val(),
|
|
|
|
|
'newPassword': password.val(),
|
|
|
|
|
'uid': ajaxify.variables.get('theirid')
|
|
|
|
|
}, function(err) {
|
|
|
|
|
currentPassword.val('');
|
|
|
|
|
password.val('');
|
|
|
|
|
password_confirm.val('');
|
|
|
|
|
passwordsmatch = false;
|
|
|
|
|
passwordvalid = false;
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
password.on('blur', onPasswordChanged);
|
|
|
|
|
password_confirm.on('blur', onPasswordConfirmChanged);
|
|
|
|
|
|
|
|
|
|
$('#changePasswordBtn').on('click', function() {
|
|
|
|
|
if ((passwordvalid && passwordsmatch) || app.isAdmin) {
|
|
|
|
|
socket.emit('user.changePassword', {
|
|
|
|
|
'currentPassword': currentPassword.val(),
|
|
|
|
|
'newPassword': password.val(),
|
|
|
|
|
'uid': ajaxify.variables.get('theirid')
|
|
|
|
|
}, function(err) {
|
|
|
|
|
currentPassword.val('');
|
|
|
|
|
password.val('');
|
|
|
|
|
password_confirm.val('');
|
|
|
|
|
passwordsmatch = false;
|
|
|
|
|
passwordvalid = false;
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.alertSuccess('[[user:change_password_success]]');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.alertSuccess('[[user:change_password_success]]');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccountEdit.changeUserPicture = function(type) {
|
|
|
|
|
var userData = {
|
|
|
|
|
function changeUserPicture(type) {
|
|
|
|
|
socket.emit('user.changePicture', {
|
|
|
|
|
type: type,
|
|
|
|
|
uid: ajaxify.variables.get('theirid')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
socket.emit('user.changePicture', userData, function(err) {
|
|
|
|
|
}, function(err) {
|
|
|
|
|
if(err) {
|
|
|
|
|
app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccountEdit.updateImages = function() {
|
|
|
|
|
function updateImages() {
|
|
|
|
|
var currentPicture = $('#user-current-picture').attr('src');
|
|
|
|
|
|
|
|
|
|
if (gravatarPicture) {
|
|
|
|
|
$('#user-gravatar-picture').attr('src', gravatarPicture);
|
|
|
|
|
$('#gravatar-box').show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#gravatar-box').hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uploadedPicture) {
|
|
|
|
|
$('#user-uploaded-picture').attr('src', uploadedPicture);
|
|
|
|
|
$('#uploaded-box').show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#uploaded-box').hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#gravatar-box').toggle(!!gravatarPicture);
|
|
|
|
|
$('#uploaded-box').toggle(!!uploadedPicture);
|
|
|
|
|
|
|
|
|
|
if (currentPicture == gravatarPicture) {
|
|
|
|
|
$('#gravatar-box .fa-check').show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#gravatar-box .fa-check').hide();
|
|
|
|
|
}
|
|
|
|
|
$('#gravatar-box .fa-check').toggle(currentPicture === gravatarPicture);
|
|
|
|
|
$('#uploaded-box .fa-check').toggle(currentPicture === uploadedPicture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentPicture == uploadedPicture) {
|
|
|
|
|
$('#uploaded-box .fa-check').show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#uploaded-box .fa-check').hide();
|
|
|
|
|
function updateSignature() {
|
|
|
|
|
function getSignatureCharsLeft() {
|
|
|
|
|
return $('#inputSignature').length ? '(' + $('#inputSignature').val().length + '/' + config.maximumSignatureLength + ')' : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#signatureCharCountLeft').html(getSignatureCharsLeft());
|
|
|
|
|
|
|
|
|
|
$('#inputSignature').on('keyup change', function(ev) {
|
|
|
|
|
$('#signatureCharCountLeft').html(getSignatureCharsLeft());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showError(element, msg) {
|
|
|
|
|
translator.translate(msg, function(msg) {
|
|
|
|
|
element.html(msg);
|
|
|
|
|
element.parent()
|
|
|
|
|
.removeClass('alert-success')
|
|
|
|
|
.addClass('alert-danger');
|
|
|
|
|
element.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSuccess(element, msg) {
|
|
|
|
|
translator.translate(msg, function(msg) {
|
|
|
|
|
element.html(msg);
|
|
|
|
|
element.parent()
|
|
|
|
|
.removeClass('alert-danger')
|
|
|
|
|
.addClass('alert-success');
|
|
|
|
|
element.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AccountEdit;
|
|
|
|
|