1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-27 02:20:28 +00:00
TiddlyWiki5/core/modules/startup/password.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

/*\
title: $:/core/modules/startup/password.js
type: application/javascript
module-type: startup
Password handling
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Export name and synchronous status
exports.name = "password";
exports.platforms = ["browser"];
2014-08-13 19:20:58 +00:00
exports.after = ["startup"];
exports.synchronous = true;
exports.startup = function() {
2014-08-28 20:43:44 +00:00
$tw.rootWidget.addEventListener("tm-set-password",function(event) {
$tw.passwordPrompt.createPrompt({
serviceName: $tw.language.getString("Encryption/PromptSetPassword"),
noUserName: true,
submitText: $tw.language.getString("Encryption/SetPassword"),
canCancel: true,
repeatPassword: true,
callback: function(data) {
if(data) {
$tw.crypto.setPassword(data.password);
}
return true; // Get rid of the password prompt
}
});
});
2014-08-28 20:43:44 +00:00
$tw.rootWidget.addEventListener("tm-clear-password",function(event) {
if($tw.browser) {
if(!confirm($tw.language.getString("Encryption/ConfirmClearPassword"))) {
return;
}
}
$tw.crypto.setPassword(null);
});
// Ensure that $:/isEncrypted is maintained properly
$tw.wiki.addEventListener("change",function(changes) {
if($tw.utils.hop(changes,"$:/isEncrypted")) {
$tw.crypto.updateCryptoStateTiddler();
}
});
};
})();