XCredentialToolImpl.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Philip James, March 9, 1992 3:50 pm PST
Willie-s, March 27, 1992 7:36 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
Rope USING [ROPE],
XCredentialTool,
Xl USING [ButtonReleaseEvent, GetPointerMapping, LastTime, PointerMapping, TimeStamp],
XNSCredentials USING [XNSLoginFromNameAndPassword],
XTk USING [WidgetNotifyProc],
XTkCredentialsWidget USING [Create, Contents, Clear],
XTkInputFocus USING [SetFocus],
XTkLabels USING [CreateLabel],
XTkShellWidgets USING [BindScreenShell, CreateShell, DestroyShell, RealizeShell, SetShellChild, ShellWidget],
XTkWidgets USING [ContainerWidget, CreateButton, CreateLabeledField, CreateXStack, CreateYStack, GetText, SetText, TextWidget];
XCredentialToolImpl: CEDAR MONITOR
IMPORTS Commander, Xl, XNSCredentials, XTkCredentialsWidget, XTkInputFocus, XTkLabels, XTkShellWidgets, XTkWidgets
EXPORTS XCredentialTool ~ {
HEIGHT: CARD ~ 20;
Status: TYPE ~ {good, bad, error, none};
CredentialStatus: TYPE ~ REF CredentialStatusRec;
CredentialStatusRec: TYPE ~ RECORD [
shell: XTkShellWidgets.ShellWidget ¬ NIL,
statusField: XTkWidgets.TextWidget ¬ NIL,
setButton: XTkWidgets.TextWidget ¬ NIL,
nameWidget: XTkWidgets.TextWidget ¬ NIL,
passwdText: XTkWidgets.TextWidget ¬ NIL,
passwdWidget: XTkWidgets.TextWidget ¬ NIL,
status: Status ¬ none,
destroyOnSuccess: BOOL ¬ FALSE];
RopeFromStatus: PROCEDURE [status: Status] RETURNS [Rope.ROPE ¬ "???"] ~ {
SELECT status FROM
good => RETURN["Status: Good"];
bad => RETURN["Status: Bad"];
error => RETURN["Status: Error"];
none => RETURN["Status: None"];
ENDCASE => RETURN["Status: Bug"];
};
Create: PUBLIC PROC [connection: REF ANY ¬ NIL, destroyOnSuccess: BOOL ¬ FALSE] ~ {
credentials: CredentialStatus ¬ NEW[CredentialStatusRec];
children: XTkWidgets.ContainerWidget;
credentials.shell ¬ XTkShellWidgets.CreateShell[
widgetSpec: [
geometry: [
size: [400, HEIGHT*3]]],
windowHeader: "Credential Tool",
iconName: "Credential Tool"];
credentials.statusField ¬ XTkLabels.CreateLabel[
widgetSpec: [
geometry: [
pos: [200, HEIGHT*2],
size: [200, HEIGHT]]],
text: RopeFromStatus[credentials.status]];
credentials.setButton ¬ XTkWidgets.CreateButton[
widgetSpec: [
geometry: [
pos: [0, HEIGHT*2],
size: [200, HEIGHT]]],
text: "Set Credentials",
hitProc: SetAction,
callData: credentials];
credentials.nameWidget ¬ XTkWidgets.CreateLabeledField[
widgetSpec: [
geometry: [
pos: [0, 0],
size: [400, HEIGHT]]],
label: "XNSUser: "];
credentials.passwdText ¬ XTkWidgets.CreateButton[
widgetSpec: [
geometry: [
pos: [0, HEIGHT],
size: [80, HEIGHT]]],
text: "Password: ",
hitProc: PasswdAction,
callData: credentials];
credentials.passwdWidget ¬ XTkCredentialsWidget.Create[
widgetSpec: [
geometry: [
pos: [80, HEIGHT],
size: [300, HEIGHT]]]];
credentials.destroyOnSuccess ¬ destroyOnSuccess;
children ¬ XTkWidgets.CreateYStack[[], LIST[
credentials.nameWidget,
XTkWidgets.CreateXStack[[], LIST[credentials.passwdText, credentials.passwdWidget]],
XTkWidgets.CreateXStack[[], LIST[credentials.setButton, credentials.statusField]]]];
XTkShellWidgets.SetShellChild[credentials.shell, children];
XTkShellWidgets.BindScreenShell[shell: credentials.shell, connection: connection];
XTkShellWidgets.RealizeShell[credentials.shell];
};
PasswdAction: XTk.WidgetNotifyProc ~ {
handle: CredentialStatus ¬ NARROW[callData];
time: Xl.TimeStamp ¬ Xl.LastTime[widget.connection];
WITH event SELECT FROM
br: Xl.ButtonReleaseEvent => {
pm: Xl.PointerMapping ~ Xl.GetPointerMapping[widget.connection];
SELECT pm[br.button] FROM
3 => XTkCredentialsWidget.Clear[handle.passwdWidget];
ENDCASE => {};
time ¬ br.timeStamp;
};
ENDCASE => {};
XTkInputFocus.SetFocus[handle.passwdWidget, time];
};
SetAction: XTk.WidgetNotifyProc ~ {
handle: CredentialStatus ¬ NARROW[callData];
name: Rope.ROPE ¬ XTkWidgets.GetText[handle.nameWidget];
passwd: Rope.ROPE ¬ XTkCredentialsWidget.Contents[handle.passwdWidget];
status: BOOL ¬ DoLogin[name, passwd];
XTkCredentialsWidget.Clear[handle.passwdWidget];
IF status THEN
handle.status ¬ good
ELSE
handle.status ¬ bad;
XTkWidgets.SetText[handle.statusField, RopeFromStatus[handle.status]];
IF handle.destroyOnSuccess AND handle.status = good THEN
XTkShellWidgets.DestroyShell[handle.shell];
};
DoLogin: ENTRY PROCEDURE [name, passwd: Rope.ROPE, strongCredentials: BOOL ¬ TRUE] RETURNS [identityWasSet: BOOL ¬ FALSE] ~ {
ENABLE UNWIND => NULL;
RETURN[XNSCredentials.XNSLoginFromNameAndPassword[name, passwd, strongCredentials]];
};
CreateTool: Commander.CommandProc ~ {
Create[];
};
Commander.Register["XCredentialTool", CreateTool, "Create a credential tool, to enter XNS credentials."];
}.