CodeCoupler UI Authentication
The system can be configured with an authentication module and an authentication application.
The module provides methods to login, logout, provide informations about the current user and its persistent configuration.
The application provides an UI to enter credentials and call the login
method of the module.
To access the module and use the provided methods you can use the property auth
of a System
instance. To request a login and start the authentication application you can call the method
login
of a System
instance.
Implement an Authentication Application
An authentication application is a regular CodeCoupler Application. The application receives at startup in addition to the options defined in the system configuration the following options:
module
: Authentication Module-
The module that should be used to call the
login
method. message
: String-
An optional message that should be shown to the user.
The only thing the application has to do is to call at any time the method login
of the given
authentication module. If the login fails (an exception will be thrown) the user should be informed
and he should retry the login.
If the login was successful the application must be closed (this.panel.close()
or this.close()
).
Implement an Authentication Module
To write a new stage class you have to extend the CodeCoupler class AuthBase
. The base class
provides methods for event handling:
on(event,handler)
, one(event,handler)
, off([event],[handler])
,
trigger(event,argments)
All other methods must be overriden by your class as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
Provided Applications and Modules
CodeCoupler provides the following applications and modules by default:
Authentication Application "Basic"
The application provides an UI to enter just a username and a password. The application is very flexible and can be adapted to your own needs.
The options that the application expects:
hooks
: Object-
An object to define hooks to adapt the behavior and appearance. See below for more details.
messages
: Object-
Define the used texts:
USERNAME
,PASSWORD
,LOGIN
The basic structure is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
We go through the following process and call the following hooks:
- Start the panel and build the HTML structure.
- Call the hook
init(panel)
. - If the hook did not return
false
: - Resize the panel.
- Set focus to the username field.
- Bind the
Enter
key to trigger the button click. - After the button was clicked:
- Call the hook
start()
. - If the hook did not return
false
:- Disable inputs elements and button. Start Button animation.
- Call the
login(username,password)
method of the module. - If succeed:
- Call the hook
done()
. - Close the application.
- Call the hook
- If failed:
- The application expects that the thrown error is just a plain string. If not a generic error message will be generated.
- Call the hook
fail(errorMessage,errorObject)
. - If the hook did not return
false
: - Enable inputs elements and button. Stop Button animation.
- Show error message.
- Resize and reposition panel.
Here an example of options which change the logo, hide the labels and translates all other messages:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Authentication Module Mockup
Just for testing purposes. You can login with the username "admin" and the password "admin".
Authentication Module Loopback
Authentication module which works with Loopback as authentication backend in combination with the
package @codecoupler/cc-api-auth
.
Will be instatiated with new AuthModLoopback(options)
. Accepts the following options object:
1 2 3 4 5 6 7 8 9 |
|
In case of an error Loopback sends an status code and a message. This message will be shown in the authentication application. You can map this messages by status code:
1 2 3 4 5 |
|