persist usernames across sessions via localStorage

pull/1/head
ansuz 8 years ago
parent 846d1135b9
commit b8a3a4d188

@ -168,10 +168,7 @@ define([
} }
}; };
var createChangeName = function(id, $container) { var setName = module.setName = function (newName) {
var buttonElmt = $container.find('#'+id)[0];
buttonElmt.addEventListener("click", function() {
Cryptpad.prompt(Messages.changeNamePrompt, '', function (newName) {
if (!(typeof(newName) === 'string' && newName.trim())) { return; } if (!(typeof(newName) === 'string' && newName.trim())) { return; }
var myUserNameTemp = newName.trim(); var myUserNameTemp = newName.trim();
if(newName.trim().length > 32) { if(newName.trim().length > 32) {
@ -182,7 +179,21 @@ define([
name: myUserName name: myUserName
}; };
addToUserList(myData); addToUserList(myData);
Cryptpad.setPadAttribute('username', myUserName);
onLocal(); onLocal();
};
var getLastName = function () {
return Cryptpad.getPadAttribute('username') || '';
};
var createChangeName = function(id, $container) {
var buttonElmt = $container.find('#'+id)[0];
var lastName = getLastName();
buttonElmt.addEventListener("click", function() {
Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) {
setName(newName);
}); });
}); });
}; };
@ -427,9 +438,16 @@ define([
}); });
} }
setEditable(true); setEditable(true);
initializing = false; initializing = false;
//Cryptpad.log("Your document is ready"); //Cryptpad.log("Your document is ready");
var lastName = getLastName();
if (typeof(lastName) === 'string' && lastName.length) {
console.log("Setting previous name to %s", lastName);
setName(lastName);
}
}; };
var cursorToPos = function(cursor, oldText) { var cursorToPos = function(cursor, oldText) {

Loading…
Cancel
Save