mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-04 23:45:04 -04:00
Update username via both socket and ajax
- socket takes care of modifying the username in the forked socket session and sending a status message to chat window - ajax request takes care of updating the flask session so that on refresh or re-opening of the URL in same browser, the username remains same
This commit is contained in:
parent
7935d07bb3
commit
9d00627df3
3 changed files with 41 additions and 8 deletions
|
@ -35,9 +35,12 @@ $(function(){
|
|||
});
|
||||
|
||||
// Keep buttons disabled unless changed or not empty
|
||||
$('#username').on('keyup',function() {
|
||||
$('#username').on('keyup',function(event) {
|
||||
if ($('#username').val() !== '' && $('#username').val() !== current_username) {
|
||||
$('#update-username').removeAttr('disabled');
|
||||
if (event.keyCode == 13) {
|
||||
current_username = updateUsername(socket);
|
||||
}
|
||||
} else {
|
||||
$('#update-username').attr('disabled', true);
|
||||
}
|
||||
|
@ -45,9 +48,7 @@ $(function(){
|
|||
|
||||
// Update username
|
||||
$('#update-username').on('click', function() {
|
||||
var username = $('#username').val();
|
||||
current_username = username;
|
||||
socket.emit('update_username', {username: username});
|
||||
current_username = updateUsername(socket);
|
||||
});
|
||||
|
||||
// Show warning of losing data
|
||||
|
@ -79,6 +80,22 @@ var emitMessage = function(socket) {
|
|||
socket.emit('text', {msg: text});
|
||||
}
|
||||
|
||||
var updateUsername = function(socket) {
|
||||
var username = $('#username').val();
|
||||
socket.emit('update_username', {username: username});
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: `http://${document.domain}:${location.port}/update-session-username`,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify({'username': username})
|
||||
}).done(function(response) {
|
||||
console.log(response);
|
||||
});
|
||||
$('#update-username').attr('disabled', true);
|
||||
return username;
|
||||
}
|
||||
|
||||
/************************************/
|
||||
/********* Util Functions ***********/
|
||||
/************************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue