Single-tier IntraWeb and RemObjects DataAbstract server PDF Print E-mail
Written by Bernhard Fischer   
Tuesday, 20 February 2007
Article Index
Single-tier IntraWeb and RemObjects DataAbstract server
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8


Now we will complete the LoginService implementation by dynamically creating a dataset & connection to verify a username and password from the web page. But first let's drop a TDASchema to define the table we want to use for verification. In our simple example this will be the USERS table again. Rename the new schema to schemaLogin , and after adding the uGlobalDataModule to the uses clause, hook it to the required connection manager GlobalDataModule.mgrConnections again. Now double-click the schemaLogin and pull the USERS table from the Data Explorer pane to the Data Tables pane. Here we will expand the USERS statement to receive username and password as parameters:



click to enlarge


After you changed the SQL statment, don't forget to recreate the parameters in the SchemaModeller!

click to enlarge

 

Now close the Schema Modeller and complete the code for the validation. This is what the completed LoginService_Impl.pas looks like (don't forget to include uDAInterfaces.pas in the uses clause):

[click to collapse source code]

 
 unit LoginService_Impl;
 
 {----------------------------------------------------------------------------}
 { This unit was automatically generated by the RemObjects SDK after reading  }
 { the RODL file associated with this project .                             }
 {                                                                          }
 { This is where you are supposed to code the implementation of your objects.   }
 {----------------------------------------------------------------------------}
 
 interface
 
 uses
  {vcl:}Classes,
  SysUtils,
  {RemObjects:}uROClientIntf,
  uROTypes,
  uROServer,
  uROServerIntf,
  uROSessions,
  {Required:}uRORemoteDataModule,
  {Used RODLs:}DataAbstract4_Intf,
  {Generated:}IWRODALibrary_Intf,
  uDAClasses;
 
 type
  { TLoginService }
  TLoginService = class(TRORemoteDataModule, ILoginService)
    schemaLogin: TDASchema;
  protected
    { ILoginService methods }
    function Login(const iUsername: string; const iPassword: string): Boolean;
 end;
 
 implementation
 
 {$R *.dfm}
 uses
  uDAInterfaces,
  {Generated:}IWRODALibrary_Invk,
  uGlobalDataModule;
 
 procedure Create_LoginService(out anInstance: IUnknown);
 begin
  anInstance := TLoginService.Create(nil);
 end;
 
 { LoginService }
 
 function TLoginService.Login(const iUsername: string; const iPassword: string): Boolean;
 var
  dsLogin: IDADataSet;
  con: IDAConnection;
 begin
  Result := False;
 
  with schemaLogin.ConnectionManager do
    con := NewConnection(GetDefaultConnectionName);
 
  dsLogin := schemaLogin.NewDataset(con, 'USERS');
  if not con.InTransaction then
    con.BeginTransaction;
  try
    with dsLogin do
    begin
      ParamByName('username').AsString := iUsername;
      ParamByName('userpass').AsString := iPassword;
      Open;
      Result := not IsEmpty;
      Close;
    end;
 
    if con.InTransaction then
      con.CommitTransaction;
 
  except
    if Assigned(con) then
      if con.InTransaction then
        con.RollbackTransaction;
  end;
 end;
 
 initialization
  TROClassFactory.Create('LoginService', Create_LoginService, TLoginService_Invoker);
 
 end.
 
 




Last Updated ( Friday, 18 January 2008 )
 
Next >