persist usernames across sessions via localStorage

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

@ -168,21 +168,32 @@ define([
}
};
var setName = module.setName = function (newName) {
if (!(typeof(newName) === 'string' && newName.trim())) { return; }
var myUserNameTemp = newName.trim();
if(newName.trim().length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myID] = {
name: myUserName
};
addToUserList(myData);
Cryptpad.setPadAttribute('username', myUserName);
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, '', function (newName) {
if (!(typeof(newName) === 'string' && newName.trim())) { return; }
var myUserNameTemp = newName.trim();
if(newName.trim().length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myID] = {
name: myUserName
};
addToUserList(myData);
onLocal();
Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) {
setName(newName);
});
});
};
@ -427,9 +438,16 @@ define([
});
}
setEditable(true);
initializing = false;
//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) {

Loading…
Cancel
Save