Commit 2be334f3 authored by Tim Peters's avatar Tim Peters

CollectPassword(): added code to supply another box to confirm

the password, and to stick on this screen until the passwords match.
I wrote this for a now-old Zope Z4I Windows installer, but there's
surely no reason to keep it secret ;-).

Also fiddled all the Pascal code to give it uniform indentation.
parent a4df0e97
...@@ -69,157 +69,175 @@ Root: HKLM; Subkey: "Software\Zope Corporation\Zope\<<VERSION>>"; Flags: uninsde ...@@ -69,157 +69,175 @@ Root: HKLM; Subkey: "Software\Zope Corporation\Zope\<<VERSION>>"; Flags: uninsde
[Code] [Code]
var var
PasswordPrompts, PasswordValues : array of String; PasswordPrompts, PasswordValues: array of String;
PasswordChars : array of char; PasswordChars: array of char;
Password: string;
DataDirValues: array of String; DataDirValues: array of String;
DataDir: String;
Password : string;
DataDir : String;
function InitializeSetup(): Boolean; function InitializeSetup(): Boolean;
begin begin
{ set up password data structures } { set up password data structures }
SetArrayLength(PasswordPrompts, 1); SetArrayLength(PasswordPrompts, 2);
PasswordPrompts[0] := 'Password:'; PasswordPrompts[0] := 'Password:';
SetArrayLength(PasswordValues, 1); PasswordPrompts[1] := 'Confirm password:';
PasswordValues[0] := ''; SetArrayLength(PasswordValues, 2);
SetArrayLength(PasswordChars, 1); PasswordValues[0] := '';
PasswordChars[0] := '*'; PasswordValues[1] := '';
Password := ''; SetArrayLength(PasswordChars, 2);
PasswordChars[0] := '*';
{ set up data dir data structures } PasswordChars[1] := '*';
SetArrayLength(DataDirValues, 1); Password := '';
DataDir := '';
{ set up data dir data structures }
Result := True; SetArrayLength(DataDirValues, 1);
DataDir := '';
Result := True;
end; end;
function CollectInstanceDir(): Boolean; function CollectInstanceDir(): Boolean;
var var
Next: Boolean; Next: Boolean;
DirOk: Boolean; DirOk: Boolean;
begin begin
DirOk := True; DirOk := True;
ScriptDlgPageSetSubCaption1('Select where Zope instance files should be installed'); ScriptDlgPageSetSubCaption1('Select where Zope instance files should be installed');
ScriptDlgPageSetSubCaption2('Select the folder to which you would like Setup to install Zope "instance" files, then click Next.'); ScriptDlgPageSetSubCaption2('Select the folder to which you would like Setup to install Zope "instance" files, then click Next.');
if DataDir = '' then DataDir:= 'C:\Zope-Instance'; if DataDir = '' then DataDir := 'C:\Zope-Instance';
if DataDirValues[0] <> '' then DataDirValues[0]:= ''; if DataDirValues[0] <> '' then DataDirValues[0] := '';
{ Ask for a dir until the user has approved one or clicked Back or Cancel } { Ask for a dir until the user has approved one or clicked Back or Cancel }
Next:= InputDir(False, DataDirValues[0], DataDir); Next:= InputDir(False, DataDirValues[0], DataDir);
if Next and FileOrDirExists(DataDir) then DirOk := False; if Next and FileOrDirExists(DataDir) then DirOk := False;
while Next and not DirOk do begin while Next and not DirOk do begin
if DataDir = '' then begin if DataDir = '' then begin
DirOk := False; DirOk := False;
MsgBox(SetupMessage(msgInvalidPath), mbError, MB_OK); MsgBox(SetupMessage(msgInvalidPath), mbError, MB_OK);
end;
if FileOrDirExists(DataDir) then begin
DirOk := MsgBox('Directory Exists' #13#13 'The directory ' +
DataDir + ' already exists. Would you like to create ' +
'instance files in that directory anyway?',
mbConfirmation, MB_YESNO) = idYes;
end;
if not DirOk then Next := InputDir(False, DataDirValues[0], DataDir);
end; end;
if FileOrDirExists(DataDir) then begin
DirOk := MsgBox('Directory Exists' #13#13 'The directory ' + DataDir + ' already exists. Would you like to create instance files in that directory anyway?', mbConfirmation, MB_YESNO) = idYes;
end;
if not DirOk then Next := InputDir(False, DataDirValues[0], DataDir);
end;
Result:=Next;
Result := Next;
end; end;
function CollectPassword(): Boolean; function CollectPassword(): Boolean;
var var
Next: Boolean; Next: Boolean;
gotPassword: Boolean;
begin begin
ScriptDlgPageSetSubCaption1('Specify administrator password'); ScriptDlgPageSetSubCaption1('Specify administrator password');
ScriptDlgPageSetSubCaption2('The login name for your Zope administrator account is "admin". When you first connect to the Zope management interface, you will need to login using the "admin" username and the password you specify below.'); ScriptDlgPageSetSubCaption2('The login name for your Zope administrator ' +
Next := InputQueryArrayEx(PasswordPrompts, PasswordChars, PasswordValues); 'account is "admin". When you first connect to the Zope management ' +
'interface, you will need to login using the "admin" username and ' +
while Next and (PasswordValues[0] = '') do begin 'the password you specify below.');
MsgBox('You must enter an administrator password', mbError, MB_OK)
Next := InputQueryArrayEx(PasswordPrompts, PasswordChars, PasswordValues); gotPassword := False;
end; repeat
Password := PasswordValues[0]; Next := InputQueryArrayEx(PasswordPrompts, PasswordChars, PasswordValues);
Result:=Next; if Next then begin
if PasswordValues[0] = '' then
MsgBox('You must enter an administrator password', mbError, MB_OK)
else if PasswordValues[0] <> PasswordValues[1] then
MsgBox('Please try again -- the passwords don''t match',
mbError, MB_OK)
else begin
gotPassword := True;
Password := PasswordValues[0]
end
end;
until gotPassword or not Next;
Result := Next;
end; end;
function DoInstanceHome():Boolean; function DoInstanceHome(): Boolean;
var var
S : String; S : String;
begin begin
S := WizardSelectedComponents(False); S := WizardSelectedComponents(False);
Result := Pos('instance', S) <> 0; Result := Pos('instance', S) <> 0;
end; end;
function DoService(): Boolean; function DoService(): Boolean;
var var
S : String; S : String;
begin begin
S := WizardSelectedTasks(False); S := WizardSelectedTasks(False);
Result := Pos('service', S) <> 0; Result := Pos('service', S) <> 0;
end; end;
function DontDoService(): Boolean; function DontDoService(): Boolean;
begin begin
Result := not DoService(); Result := not DoService();
end; end;
function ScriptDlgPages(CurPage: Integer; BackClicked: Boolean): Boolean; function ScriptDlgPages(CurPage: Integer; BackClicked: Boolean): Boolean;
var var
Next : Boolean; Next : Boolean;
CurSubPage : Integer; CurSubPage : Integer;
begin begin
Next:=True; Next:=True;
if ( (not BackClicked and (CurPage = wpSelectTasks)) or (BackClicked and (CurPage = wpReady)) ) if ( (not BackClicked and (CurPage = wpSelectTasks)) or (BackClicked and (CurPage = wpReady)) )
and DoInstanceHome() then begin and DoInstanceHome() then begin
if not BackClicked then CurSubPage:=0 else CurSubPage:=1; if not BackClicked then CurSubPage:=0 else CurSubPage:=1;
ScriptDlgPageOpen(); ScriptDlgPageOpen();
ScriptDlgPageSetCaption('Instance Setup'); ScriptDlgPageSetCaption('Instance Setup');
while (CurSubPage >=0) and (CurSubPage <=1) and not Terminated do begin while (CurSubPage >=0) and (CurSubPage <=1) and not Terminated do begin
case CurSubPage of case CurSubPage of
0: Next:=CollectInstanceDir(); 0: Next := CollectInstanceDir();
1: Next:=CollectPassword(); 1: Next := CollectPassword();
end; end;
if Next then CurSubPage := CurSubPage +1 else CurSubPage := CurSubPage -1; if Next then CurSubPage := CurSubPage +1 else CurSubPage := CurSubPage -1;
end; end;
if not BackClicked then if not BackClicked then
Result := Next Result := Next
else else
Result := not Next; Result := not Next;
ScriptDlgPageClose(not Result); ScriptDlgPageClose(not Result);
end;
end;
Result:=Next; Result := Next;
end; end;
function NextButtonClick(CurPage: Integer): Boolean; function NextButtonClick(CurPage: Integer): Boolean;
begin begin
Result := ScriptDlgPages(CurPage, False); Result := ScriptDlgPages(CurPage, False);
end; end;
function BackButtonClick(CurPage: Integer): Boolean; function BackButtonClick(CurPage: Integer): Boolean;
begin begin
Result := ScriptDlgPages(CurPage, True); Result := ScriptDlgPages(CurPage, True);
end; end;
function GetPassword(Default: String): String; function GetPassword(Default: String): String;
begin begin
Result := Password; Result := Password;
end; end;
function GetDataDir(Default : String):String; function GetDataDir(Default : String):String;
begin begin
Result := DataDir; Result := DataDir;
end; { GetInstanceDir } end; { GetInstanceDir }
function IsAdministrator(): Boolean; function IsAdministrator(): Boolean;
begin begin
Result := IsAdminLoggedOn(); Result := IsAdminLoggedOn();
end; end;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment