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.
Table of Contents
Location
You can find the CustomLogin sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | 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.
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.
- Navigate to one of the locations given above and open:
- Delphi: CustomLoginPackage.dpk.
- C++: CustomLoginPackageCpp.cbproj.
- Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
- 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.
- 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.
- On the Project Manager, right-click on ProjectGroup1.
- Click Add Existing Project….
- Navigate to one of the locations given above and open:
- Delphi: CustomLoginClient.dproj.
- C++: CustomLoginClientCpp.cbproj.
- Press F9 or choose Run > Run.
- Select Use Custom Resource (CustomLogin) to use your Window credentials to authenticate in the EMS Server.
- 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.
- 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.
- Click the Update Fields button to modify and update the custom description field in the EMS Server.
- Click the Delete
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:
- Identifies the address of the RAD Server Engine (EMS Server): http://localhost:8080.
- Set the value of TEMSProvider.LoginResource property to CustomLogin (the custom resource from the sample).
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