Learn How To Implement A Custom Resource EMS Package To Extend RAD Server In Delphi

The CustomLogin sample is a server-client EMS demo, that demonstrates how to implement custom Login and Signup endpoints in a custom resource.

It requires InterBase to be installed on the machine to connect to the EMS server. Make sure that the EMS Server is running before you run the client project.

Location

You can find the CustomLogin sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to either:
    • Object PascalDatabaseEMSCustomLogin
    • CPPDatabaseEMSCustomLogin
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

How to Use the Sample

Run the EMS CustomLogin Package

When you run the CustomLoginPackage project, the EMSDevServer starts automatically.

The supported platforms for this sample are: 32-bit and 64-bit Windows.

  1. Navigate to one of the locations given above and open:
    • Delphi: CustomLoginPackage.dpk.
    • C++: CustomLoginPackageCpp.cbproj.
  2. Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
  3. The EMS Development Server opens.If it is the first time you are using EMS on the machine, you need to run the configuration wizard in order to create the EMS server configuration file.
    • When the Confirm dialog opens, click Yes.
    • Click Next until the installation finishes.
  4. The EMS Development Server starts automatically.

Run the Client Application

The client expects the EMSDevServer to be running at localhost:8080. If you are running the server at a different address, modify the properties of the TEMSProvider component.

To run the sample on a different machine that the EMS Server, change the URLHost property of the TEMSProvider component to the IP address from the machine where the EMS Server runs.Note: The TEMSProvider component is placed in the CustomLoginClientU unit.

  1. On the Project Manager, right-click on ProjectGroup1.
  2. Click Add Existing Project….
  3. Navigate to one of the locations given above and open:
    • Delphi: CustomLoginClient.dproj.
    • C++: CustomLoginClientCpp.cbproj.
  4. Press F9 or choose Run > Run.
  5. Select Use Custom Resource (CustomLogin) to use your Window credentials to authenticate in the EMS Server.
  6. In the Signup or Login tabs, insert a UserName and Password and click the buttons:
    • Use the Signup tab to sign up a new user and log on to the EMS Server with that user.
    • Use the Login tab if you previously created an account. Click the Logout button to log off from the EMS Server.
  7. In the User tab you can manage your user data:
    • Click the Delete user to delete the user from the EMS Server.
    • Click the Retrieve Fields button to get the custom description field from the EMS Server.

    { “description”:”New info” }

    • Click the Update Fields button to modify and update the custom description field in the EMS Server.

Note: The custom Login and Signup endpoints validate the UserName and Password against Windows users by calling WinApi.Windows.LogonUser. You need to sign up with valid Windows credentials.

Implementation

EMS Custom Package

The custom login package implements custom Login and Signup endpoints, by matching the signature of the Users.LoginUser and Users.SignupUser and implementing these methods. The custom public endpoints are:

  • CustomSignupUser to sign up a new EMS user.
  • CustomLoginUser to log in an existing EMS user.

Client Application

The client application has a TEMSProvider component, that:

The information is managed with TJSONObject and TJSONArray.

Please visit the original Embarcadero post for more information about this samble:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/EMS.CustomLogin_Sample