1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| {
Fonction permettant à l'utilisateur de se connecter
}
procedure TUtilisateurResource1.Login(const AContext: TEndpointContext;
const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
myObject: TJSONObject;
userEmail, passcode: string;
begin
try
myObject := ARequest.Body.GetObject;
userEmail := myObject.GetValue('email').Value;
passcode := myObject.GetValue('mdp').Value;
FDQuery1.Close;
FDQuery1.SQL.Clear;
FDQuery1.SQL.Text := 'SELECT COUNT(*) FROM utilisateur WHERE email = :userEmail';
FDQuery1.ParamByName('userEmail').Value := userEmail;
FDQuery1.Open();
if (not FDQuery1.IsEmpty) and (FDQuery1.Fields[0].AsInteger > 0) then
begin
FDQuery1.Close();
FDQuery1.SQL.Text := 'SELECT COUNT(*) FROM utilisateur WHERE email = :userEmail AND mdp = :passcode';
FDQuery1.ParamByName('userEmail').Value := userEmail;
FDQuery1.ParamByName('passcode').Value := passcode;
FDQuery1.Open();
if (not FDQuery1.IsEmpty) and (FDQuery1.Fields[0].AsInteger > 0) then
begin
AResponse.Body.SetValue(TJSONTrue.Create, True);
AResponse.StatusCode := 200;
end
else
begin
AResponse.Body.SetValue(TJSONFalse.Create, True);
AResponse.StatusCode := 401; // Unauthorized
end;
end
else
begin
AResponse.Body.SetValue(TJSONFalse.Create, True);
AResponse.StatusCode := 401; // Unauthorized
end;
finally
FDQuery1.Close();
end;
end; |
Partager