Function TForm1.Login2ACloud(aUsername,aPassword,aLocale,anActiveVersion :
String; aPremiumStatus:Integer; IsSilentMode:Boolean):Boolean;
Var
iDHTTP: TIdHttp;
Params: TStringStream;
JSON: ISuperObject;
begin
if NOT ((Length(EaCloudUsername.Text) >= 5)
AND (Pos('
@', EaCloudUsername.Text) > 1 ))
then begin
Showmessage(Txt[715,L]);
//invalid e-mail adress
exit;
end;
IF (Length(EaCloudPassword.Text) < 4)
then begin
Showmessage(Txt[718,L]);
//password missing or invalid
exit;
end;
IdHttp := TIdHttp.Create;
Params := TStringStream.create('
');
//1.) Prepare and send a HTTP-Post to the CloudServer asking for LoggingIn
try
JSON := SO();
JSON['
UID'] := SO('
"' + CreateGuid + '
"');
JSON['
activeversion'] := SO(anActiveVersion);
JSON['
locale'] := SO(aLocale);
JSON['
password'] := SO(aPassword);
JSON['
premium'] := SO(aPremiumStatus);
JSON['
username'] := SO(aUsername);
JSONParams := JSON.AsJSon();
Params.WriteString(JSONParams);
iDHTTP.HandleRedirects := True;
iDHTTP.Request.BasicAuthentication := True;
iDHTTP.Request.Authentication := TIdBasicAuthentication.Create;
iDHTTP.Request.Authentication.Username := EaCloudUsername.Text;
iDHTTP.Request.Authentication.Password := EaCloudPassword.Text;
IdHTTP.Request.ContentType := '
application/json';
IdHTTP.Response.KeepAlive := False;
try
JSONResponse := IdHTTP.Post(aCloudServer + '
users/login.json', Params);
except
on E:
Exception do
IF (IsSilentMode = FALSE)
then showmessage('
Error encountered during POST: ' + E.
Message);
end;
finally
IdHTTP.Free;
end;
//2.) Now we interprete if the connection was succesful and write data into the record "aCloudLogin"
JSON := SO(JSONResponse);
// Interprete the JSON response to the JSON Super-Object (SO)
aCloudLogin.id := JSON.O['
return'].S['
id'];
if (POS('
OK', Uppercase(JSON.O['
return'].S['
response']) ) > 0)
then aCloudLogin.LogonSuccesfull := True
else aCloudLogin.LogonSuccesfull := FALSE;
If (aPremiumStatus = 0)
then aCloudLogin.PremiumStatus := True
else aCloudLogin.PremiumStatus := FALSE;
aCloudLogin.Username := aUsername;
aCloudLogin.Password := aPassword;
Result:= aCloudLogin.LogonSuccesfull;
end;