From 5da2776f5d941d448ab85cf23afbe1ad5e95ed2b Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 29 Sep 2015 13:47:00 +0200 Subject: [PATCH] Added password entry support --- README.md | 4 ++++ URestemplateApp.pas | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 75ed1c0..a8e09d7 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ Once the first none-empty line is unrecognized (no command found), the parser wi : Prompts the user for the input of ``. If the value has been given in a previous run, it is suggested as default value so the user can simply accept the "last" value. This eases re-runs of the same profile with only minor (or no) changes. This can be repeated multiple times. +`Ask#` +: Prompts the user for the hidden input of ``. This can be used to input passwords. These values are not persisted and therefore no default values are suggested. + This can be repeated multiple times. + `Header ` : Sets the given http header for the request. This can be repeated multiple times. diff --git a/URestemplateApp.pas b/URestemplateApp.pas index 2dbe778..484146d 100644 --- a/URestemplateApp.pas +++ b/URestemplateApp.pas @@ -149,10 +149,11 @@ end; function TRestemplateApplication.ProcessCommand(ALine: String): Boolean; begin Result := False; - if AnsiStartsStr('Ask ', ALine) then + //The first char after "Ask" is treated as "mode". "#" means password. + if AnsiStartsStr('Ask', ALine) then begin Result := True; - CmdAskUser(Copy(ALine, 5, Length(ALine))); + CmdAskUser(Copy(ALine, 4, Length(ALine))); end else if AnsiStartsStr('Header ', ALine) then begin @@ -191,17 +192,35 @@ end; procedure TRestemplateApplication.CmdAskUser(AName: String); var + mode: TPromptMode; value, default: String; begin - default := FSessionIni.ReadString(FTemplateName, AName, ''); - value := Prompt(AName, default); + if Length(AName) < 2 then + raise Exception.Create('Asking without variable!'); + + if AName[1] <> ' ' then + mode := pmPassword + else + mode := pmNormal; + + AName := Copy(AName, 2, Length(AName)); + + if mode = pmNormal then + begin + default := FSessionIni.ReadString(FTemplateName, AName, ''); + value := Prompt(AName, default); + end else + begin + value := Prompt(AName, mode); + end; if value = '' then Halt(3); //Cancelled FParser.Fields.Add(AName, value); - FSessionIni.WriteString(FTemplateName, AName, value); + if mode = pmNormal then + FSessionIni.WriteString(FTemplateName, AName, value); end; procedure TRestemplateApplication.CmdHeader(AHeader: String);