r=kaie sr=blizzard bug# 87656

[enables selecting token in change pswd dialog]
This commit is contained in:
rangansen%netscape.com 2001-10-11 21:18:08 +00:00
parent 86d595922a
commit 0f707586ec
5 changed files with 116 additions and 50 deletions

View File

@ -38,9 +38,14 @@
<vbox style="margin: 5px;" flex="1">
<hbox>
<text value="&setPassword.tokenName.label;:"/>
<hbox align="center">
<text value="&setPassword.tokenName.label;: "/>
<text id="tokenName" />
<menulist id="tokenMenu" oncommand="onMenuChange()">
<menupopup/>
</menulist>
</hbox>
<!--
<menulist id="signerList" disabled="true">
@ -50,8 +55,6 @@
</menupopup>
</menulist>
-->
</hbox>
<separator/>
<groupbox orient="vertical">
@ -64,6 +67,14 @@
<row>
<text value="&setPassword.oldPassword.label;"/>
<textbox id="oldpw" type="password"/>
<!-- This textbox is inserted as a workaround to the fact that making the 'type'
& 'disabled' property of the 'oldpw' textbox toggle between ['password' &
'false'] and ['text' & 'true'] - as would be necessary if the menu has more
than one tokens, some initialized and some not - does not work properly. So,
either the textbox 'oldpw' or the textbox 'message' would be displayed,
depending on the state of the token selected
-->
<textbox id="message" disabled="true" />
</row>
<row>
<text value="&setPassword.newPassword.label;"/>

View File

@ -170,12 +170,14 @@ function enableButtons()
// so grab the token type
var selected_token = selected_slot.getToken();
if (selected_token != null) {
if (selected_token.needsLogin()) {
if (selected_token.needsLogin() || !(selected_token.needsUserInit)) {
pw_toggle = "false";
if (selected_token.isLoggedIn()) {
logout_toggle = "false";
} else {
login_toggle = "false";
if(selected_token.needsLogin()) {
if (selected_token.isLoggedIn()) {
logout_toggle = "false";
} else {
login_toggle = "false";
}
}
}
}

View File

@ -26,56 +26,104 @@ const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsPKCS11ModuleDB = "@mozilla.org/security/pkcs11moduledb;1";
const nsIPKCS11ModuleDB = Components.interfaces.nsIPKCS11ModuleDB;
const nsIPKCS11Slot = Components.interfaces.nsIPKCS11Slot;
const nsIPK11Token = Components.interfaces.nsIPK11Token;
var params;
var tokenName;
var tokenName="";
var pw1;
function onLoad()
{
pw1 = document.getElementById("pw1");
try {
params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
tokenName = params.getString(1)
}catch(exception)
{tokenName = self.name;}
if ("arguments" in window) {
params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
tokenName = params.GetString(1);
if(tokenName=="" || tokenName=="_blank") {
var sectokdb = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
var tokenList = sectokdb.listTokens();
var enumElement;
i=0;
var menu = document.getElementById("tokenMenu");
try {
for ( ; !tokenList.isDone(); tokenList.next()) {
enumElement = tokenList.currentItem();
var token = enumElement.QueryInterface(nsIPK11Token);
if(token.needsLogin() || !(token.needsUserInit)) {
var menuItemNode = document.createElement("menuitem");
menuItemNode.setAttribute("value", token.tokenName);
menuItemNode.setAttribute("label", token.tokenName);
menu.firstChild.appendChild(menuItemNode);
if (i == 0) {
menu.selectedItem = menuItemNode;
tokenName = token.tokenName;
}
i++;
}
}
}catch(exception){}
} else {
tokenName = self.name;
var sel = document.getElementById("tokenMenu");
sel.setAttribute("hidden", "true");
var tag = document.getElementById("tokenName");
tag.setAttribute("value",tokenName);
}
process();
}
// Set token name in display
var t = document.getElementById("tokenName");
t.setAttribute("value", tokenName);
function onMenuChange()
{
//get the selected token
var list = document.getElementById("tokenMenu");
tokenName = list.value;
var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
process();
}
// If the token is unitialized, don't use the old password box.
// Otherwise, do.
var secmoddb = Components.
classes[nsPKCS11ModuleDB].
getService(nsIPKCS11ModuleDB);
var slot = secmoddb.findSlotByName(tokenName);
if (slot) {
var oldpwbox = document.getElementById("oldpw");
var status = slot.status;
if (status == nsIPKCS11Slot.SLOT_UNINITIALIZED
|| status == nsIPKCS11Slot.SLOT_READY) {
oldpwbox.setAttribute("disabled", "true");
oldpwbox.setAttribute("type", "text");
oldpwbox.setAttribute("value",
bundle.GetStringFromName("password_not_set"));
if (status == nsIPKCS11Slot.SLOT_READY) {
oldpwbox.setAttribute("inited", "empty");
} else {
oldpwbox.setAttribute("inited", "true");
}
// Select first password field
document.getElementById('pw1').focus();
} else {
// Select old password field
oldpwbox.setAttribute("inited", "false");
oldpwbox.focus();
}
}
function process()
{
var secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
// If the token is unitialized, don't use the old password box.
// Otherwise, do.
var slot = secmoddb.findSlotByName(tokenName);
if (slot) {
var oldpwbox = document.getElementById("oldpw");
var msgBox = document.getElementById("message");
var status = slot.status;
if (status == nsIPKCS11Slot.SLOT_UNINITIALIZED
|| status == nsIPKCS11Slot.SLOT_READY) {
oldpwbox.setAttribute("hidden", "true");
msgBox.setAttribute("value", bundle.GetStringFromName("password_not_set"));
msgBox.setAttribute("hidden", "false");
if (status == nsIPKCS11Slot.SLOT_READY) {
oldpwbox.setAttribute("inited", "empty");
} else {
oldpwbox.setAttribute("inited", "true");
}
// Select first password field
document.getElementById('pw1').focus();
} else {
// Select old password field
oldpwbox.setAttribute("hidden", "false");
msgBox.setAttribute("hidden", "true");
oldpwbox.setAttribute("inited", "false");
oldpwbox.focus();
}
}
if (params) {
// Return value 0 means "canceled"

View File

@ -36,6 +36,8 @@
const nsIPK11Token = Components.interfaces.nsIPK11Token;
const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsDialogParamBlock = "@mozilla.org/embedcomp/dialogparam;1";
var internal_token;
@ -95,9 +97,10 @@ function changePasswordSettings()
function ChangePW()
{
window.open("chrome://pippki/content/changepassword.xul",
internal_token.tokenName,
"chrome,resizable=1,modal=1,dialog=1");
var params = Components.classes[nsDialogParamBlock].getService(nsIDialogParamBlock);
params.SetString(1,"_blank");
window.openDialog("chrome://pippki/content/changepassword.xul","",
"chrome,resizable=1,modal=1,dialog=1",params);
}
function ResetPW()

View File

@ -184,7 +184,9 @@ NS_IMETHODIMP nsPK11Token::GetMinimumPasswordLength(PRInt32 *aMinimumPasswordLen
/* readonly attribute boolean needsUserInit; */
NS_IMETHODIMP nsPK11Token::GetNeedsUserInit(PRBool *aNeedsUserInit)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aNeedsUserInit = PK11_NeedUserInit(mSlot);
return NS_OK;
}
/* boolean checkPassword (in wstring password); */