Ask for username and password to authenticate (closes #2)
This commit is contained in:
parent
7b8594adef
commit
67bf8f70f2
@ -2,10 +2,8 @@ program downloader;
|
||||
|
||||
uses fphttpclient, base64, opensslsockets, fpjson, jsonparser, SysUtils, process, Classes, libtar;
|
||||
|
||||
const
|
||||
authString = '***REMOVED***';
|
||||
|
||||
var
|
||||
authString: String;
|
||||
gameId: Integer;
|
||||
gameData: TJSONData;
|
||||
client: TFPHTTPClient;
|
||||
@ -105,22 +103,51 @@ begin
|
||||
tarFile.Destroy;
|
||||
end;
|
||||
|
||||
function authenticate(client: TFPHTTPClient): Boolean;
|
||||
const
|
||||
url = 'https://rpi.narnian.us';
|
||||
|
||||
var
|
||||
username, password: String;
|
||||
|
||||
begin
|
||||
Write('Enter username: ');
|
||||
ReadLn(username);
|
||||
Write('Enter password: ');
|
||||
ReadLn(password);
|
||||
authString := username + ':' + password;
|
||||
client.AddHeader('Authorization', 'Basic '+base64.EncodeStringBase64(authString));
|
||||
client.AllowRedirect := true;
|
||||
try
|
||||
client.Get(url);
|
||||
authenticate := true;
|
||||
except
|
||||
authenticate := false;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
if ParamCount > 0 then
|
||||
begin
|
||||
gameId := StrToInt(ParamStr(1));
|
||||
client := TFPHTTPClient.Create(nil);
|
||||
client.AddHeader('Authorization', 'Basic '+base64.EncodeStringBase64(authString));
|
||||
if getGameData(client, gameId, gameData) then
|
||||
if authenticate(client) then
|
||||
begin
|
||||
tarFile := downloadGameTar(client, gameId);
|
||||
extractTar(tarFile);
|
||||
DeleteFile(tarFile);
|
||||
WriteLn('Download finished');
|
||||
if getGameData(client, gameId, gameData) then
|
||||
begin
|
||||
tarFile := downloadGameTar(client, gameId);
|
||||
extractTar(tarFile);
|
||||
DeleteFile(tarFile);
|
||||
WriteLn('Download finished');
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn('Invalid game id given');
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn('Invalid game id given');
|
||||
WriteLn('Invalid username or password');
|
||||
end;
|
||||
end
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user