Those of you who have started using Qodly Studio for 4D already know how powerful this new tool is for developing business web applications. If you haven’t yet, find here more information on getting started.
Apps made with Qodly Studio for 4D rely on the REST APIs. 4D 20 R5 is shipped with a great new feature: “Force Login” mode.
With Force Login mode, a 4D Client license is only consumed when users successfully log in and begin working with your application’s data and logic.
Keep reading to find out more! And don’t forget to download our demo to see it in action!
What is Force Login Mode?
Qodly web forms are not HTML. Indeed, Qodly Studio for 4D describes your form as a JSON file, later rendered in the end-user web browser as HTML.
For a Qodly form to be rendered in the end-user web browser, a REST request is triggered from the browser to download the form’s JSON from the server.
Further end-user actions on the form will also trigger REST requests to handle data and call functions of ORDA Data model classes on the server.
Before 4D 20 R5, as for any other REST requests, the server creates and maintains a web session to host the Session storage and session privileges, and a 4D Client license is consumed simultaneously.
Consequently, if you implement a simple authentication form (login + password inputs) with Qodly Studio for 4D, as soon as your end-user reaches this form, a 4D Client license is consumed before the authentication process has even started.
The consumed 4D client license is only released when the web session is closed after an inactivity timeout of at least one hour (or a server restart). This can lead to a lack of available 4D client licenses to allow users to work with your application.
We are aware this behavior could be enhanced, that’s why:
With 4D 20 R5, you can use the new “Force login” mode while working with the REST APIs.
This mode greatly benefits Qodly Studio for 4D applications as it improves this process. It helps you control the consumption of 4D client licenses, and you can now free a 4D client license when the user has finished using the application.
To summarize
With Force Login mode, licenses are consumed only when users start working with the s data and logic your REST server serves. This means:
- Reduced License Consumption: Login forms no longer consume licenses.
- Improved User Experience: Users can attempt login without impacting available licenses.
- Better Resource Management: The license is freed once a user quits the application.
Free a 4D Client license at any time
The session can be quit by simply triggering the Logout standard action, and a 4D Client license can be released.
This is a significant enhancement, so let’s dive into more details to learn how you can benefit from this feature.
How to Activate Force Login Mode
Enabling Force Login mode is simple. Just navigate to the Roles and Privileges section and activate it.
This updates your project’s roles.json file accordingly.
{
"permissions": {
"allowed": [
]
},
"privileges": [
],
"roles": [
],
"forceLogin": true
}
Detailed Behavior Breakdown
Once this mode is activated:
- Descriptive REST requests (i.e., requests such as rest/$catalog or rest/$getWebForm to render a web form) do not consume any license.
- Other REST requests (e.g., requests handling data or calling ORDA Data model classes functions) are rejected until successful authentication is completed.
- You must implement a function whose name must be authentify() in the datastore class. This function handles the authentication. This is the only descriptive REST request accepted without a successful authentication.
Once the authentication is successful, all the REST requests are accepted, and a 4D client license is consumed.
A successful authentication means calling the Session.setPrivileges() function.
Here is the timeline of this:
Example: Salesperson Application
This example features an application salespersons use to work with their customer’s files.
The end user renders a web form with a datasource of type entity selection (Customers dataclass) with the All initial value.
This error is received because no successful authentication has been done yet:
However, the end user can render this simple web form that does not handle data or call any function when loaded. No 4D Client license is consumed at this time.
When the end user clicks on the Go button, the authentify() function is called. It has been implemented in the datastore class.
exposed Function authentify($credentials : Object) : Text
var $salesPersons : cs.SalesPersonsSelection
var $sp : cs.SalesPersonsEntity
$salesPersons:=ds.SalesPersons.query("identifier = :1"; $credentials.identifier)
$sp:=$salesPersons.first()
If ($sp#Null)
If (Verify password hash($credentials.password; $sp.password))
Session.clearPrivileges()
Session.setPrivileges("")
return "Authentication successful"
Else
return "Wrong password"
End if
Else
return "Wrong user"
End if
This call is accepted.
If the authentication fails, the Session.setPrivileges() function is not called. Thus, no license is consumed + no descriptive REST requests remain rejected.
If the authentication is successful, the Session.setPrivileges() function is called. Thus, a 4D client license is consumed, and any REST request is now accepted. You can then start working efficiently with your data.
Note: In this example, an empty string is passed to the Session. Use the setPrivileges() function to authenticate as a guest. Of course, the privileges corresponding to the users’ authenticating themselves can be set.
Further, you can offer your end users a disconnect feature thanks to the logout standard action mentioned above. The session will be cleared of its privileges, and the end user will be back in the “not authenticated state”: only descriptive REST requests are accepted, and they must authenticate themselves again to work with the data.
Conclusion
With Force Login mode in 4D 20 R5, you can optimize 4D client license consumption in your Qodly Studio for 4D web applications. This improves user experience and server resource management. Let us know what you think about this feature on the 4D Forums!