unit Agent; interface uses SysUtils, ObserverPattern, ApplicationContext, UserServerService; // Resource strings are stored as resources and linked into the executable or // library so that they can be modified without recompiling the program. resourcestring USER_SERVER_URL = 'http://cacheaccept2010:57772/csp/dev1/WS.Sys.Toegang.UserServer.cls'; APPLICATION_NAME = 'vhintra'; DOMAIN_NAME = '1'; type TAgent = class private FUserServerSoap: UserServerSoap; procedure RegistreerLoginGegevens(UserServerServiceContext: TUserServerServiceContext; pxLogInObj: pxLogIn); procedure RegistreerMislukteLogin(UserServerServiceContext: TUserServerServiceContext; pxStatusObj: pxStatus); procedure RegistreerLogout(UserServerServiceContext: TUserServerServiceContext); procedure RegistreerMislukteLogout(UserServerServiceContext: TUserServerServiceContext; pxStatusObj: pxStatus); public Constructor Create(); overload; procedure GebruikerAanmelden(GebruikersNaam: string; Wachtwoord: string; UserServerServiceContext: TUserServerServiceContext); procedure GebruikerAfmelden(UserServerServiceContext: TUserServerServiceContext); end; implementation constructor TAgent.Create(); begin FUserServerSoap := UserServerService.GetUserServerSoap(false, USER_SERVER_URL, nil); end; procedure TAgent.GebruikerAanmelden(GebruikersNaam: string; Wachtwoord: string; UserServerServiceContext: TUserServerServiceContext); var LogInData: UserServerService.LogIn; LogInResponseObj: UserServerService.LogInResponse; begin LogInData := nil; LogInResponseObj := nil; try // Request LogInData := UserServerService.LogIn.Create(); LogInData.Application_ := APPLICATION_NAME; LogInData.GebruikersNaam := GebruikersNaam; LogInData.Wachtwoord := Wachtwoord; LogInData.Domein := DOMAIN_NAME; LogInData.pxLogIn := nil; // Ongebruikt LogInResponseObj := FUserServerSoap.LogIn(LogInData); // Response if LogInResponseObj.pxLogIn <> nil then begin // Gelukt RegistreerLoginGegevens(UserServerServiceContext, LogInResponseObj.pxLogIn); end else begin // Mislukt RegistreerMislukteLogin(UserServerServiceContext, LogInResponseObj.LogInResult); end; finally LogInData.Free(); LogInResponseObj.Free(); end; end; procedure TAgent.RegistreerLoginGegevens(UserServerServiceContext: TUserServerServiceContext; pxLogInObj: pxLogIn); begin // Andere velden juist zetten UserServerServiceContext.IsOK := True; UserServerServiceContext.ErrorMessage := ''; UserServerServiceContext.InternalErrorMessage := ''; UserServerServiceContext.SessionKey := pxLogInObj.SessionKey; UserServerServiceContext.GebruikersNaam := pxLogInObj.GebruikersNaam; UserServerServiceContext.Changed(); end; procedure TAgent.RegistreerMislukteLogin(UserServerServiceContext: TUserServerServiceContext; pxStatusObj: pxStatus); begin // Ander velden leegmaken UserServerServiceContext.SessionKey := ''; UserServerServiceContext.GebruikersNaam := ''; UserServerServiceContext.IsOK := pxStatusObj.IsOK; UserServerServiceContext.ErrorMessage := pxStatusObj.Message_; UserServerServiceContext.InternalErrorMessage := pxStatusObj.InternalMessage; UserServerServiceContext.Changed(); end; procedure TAgent.GebruikerAfmelden(UserServerServiceContext: TUserServerServiceContext); var LogOutData: UserServerService.LogOut; LogOutResponseObj: UserServerService.LogOutResponse; begin LogOutData := nil; LogOutResponseObj := nil; try // Skip als de gebruikers nooit was ingelogd if UserServerServiceContext.SessionKey = '' then exit; // Request LogOutData := UserServerService.LogOut.Create(); LogOutData.SessionKey := UserServerServiceContext.SessionKey; LogOutResponseObj := FUserServerSoap.LogOut(LogOutData); // Response if LogOutResponseObj.LogOutResult = nil then begin // Gelukt RegistreerLogout(UserServerServiceContext); end else begin // Mislukt RegistreerMislukteLogout(UserServerServiceContext, LogOutResponseObj.LogOutResult); end; finally LogOutData.Free(); LogOutResponseObj.Free(); end; end; procedure TAgent.RegistreerLogout(UserServerServiceContext: TUserServerServiceContext); begin UserServerServiceContext.IsOK := True; UserServerServiceContext.ErrorMessage := ''; UserServerServiceContext.InternalErrorMessage := ''; UserServerServiceContext.SessionKey := ''; UserServerServiceContext.GebruikersNaam := ''; UserServerServiceContext.Changed(); end; procedure TAgent.RegistreerMislukteLogout(UserServerServiceContext: TUserServerServiceContext; pxStatusObj: pxStatus); begin UserServerServiceContext.IsOK := pxStatusObj.IsOK; UserServerServiceContext.ErrorMessage := pxStatusObj.Message_; UserServerServiceContext.InternalErrorMessage := pxStatusObj.InternalMessage; UserServerServiceContext.Changed(); end; end.