EMS.CustomLogin Sample

From RAD Studio Code Examples
Jump to: navigation, search

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.


You can find the CustomLogin sample project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to either:
    • Object Pascal\Database\EMS\CustomLogin
    • CPP\Database\EMS\CustomLogin
  • 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.


This sample demonstrates how to implement a custom resource EMS package to extend the EMS Server. The CustomLogin resource is used to log on and sign up to the EMS Server by using Windows credentials.

The first part consists of creating an EMS Package with a new resource (CustomLogin), that implements custom Login and Signup endpoints for your EMS Server. Once you run the package, the CustomLogin resource is registered on the EMS server, and the EMS Resource endpoints (Login and Signup) can be accessed by an EMS client application using REST call.

The client application allows you to use the custom Login and Signup endpoints (from the CustomLogin package) and the standard Users.SignupUser and Users.LoginUser endpoints from the Users resource.

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.

In the EMS Development Server window you can see the CustomLogin resource loaded to the server:


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.


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.

The custom package uses the TEMSInternalAPI to call the endpoints of the Users resource in the EMS Server.

The custom package validates credentials using Windows Logon API.

Client Application

The client application has a TEMSProvider component, that:

The client application also has the following components:

  • A TBackendAuth component to standard log in and sign up users.
  • A ActionList for the actions the client application can do against the EMS Server (Login, Logout, Signup, DeleteUser, RetrieveUserFields, UpdateUserFields, UseCustomResource).

You can authenticate in the EMS Server by using:

  • If Use Custom Resource is selected, the EMS client application uses the CustomLogin resource to authenticate in the EMS Server. Your Windows credentials are used to authenticate in this sample.
  • If Use Custom Resource is not selected, standard Login and Signup is used to authenticate in the EMS Server.

The information is managed with TJSONObject and TJSONArray.


See Also