2014-05-05 09:17:50 +00:00
|
|
|
/*\
|
|
|
|
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"];
|
2014-05-05 09:17:50 +00:00
|
|
|
exports.synchronous = true;
|
|
|
|
|
|
|
|
exports.startup = function() {
|
2014-08-28 20:43:44 +00:00
|
|
|
$tw.rootWidget.addEventListener("tm-set-password",function(event) {
|
2014-05-05 09:17:50 +00:00
|
|
|
$tw.passwordPrompt.createPrompt({
|
2014-10-07 13:35:42 +00:00
|
|
|
serviceName: $tw.language.getString("Encryption/PromptSetPassword"),
|
2014-05-05 09:17:50 +00:00
|
|
|
noUserName: true,
|
|
|
|
submitText: "Set password",
|
|
|
|
canCancel: true,
|
2014-10-06 09:22:09 +00:00
|
|
|
repeatPassword: true,
|
2014-05-05 09:17:50 +00:00
|
|
|
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) {
|
2014-10-07 13:35:42 +00:00
|
|
|
if($tw.browser) {
|
|
|
|
if(!confirm($tw.language.getString("Encryption/ConfirmClearPassword"))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-05-05 09:17:50 +00:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|