Identity Management initialization
To initialize Identity Management, you'll need to set the setUsePianoIdUserProvider boolean on the tp global object to true. Like so:
tp.push(["setUsePianoIdUserProvider", true ]);
You do not need to set the userRef or pass Piano any additional information. We will determine if the user is logged in or not and present the appropriate login or registration modals necessary for checkout to proceed.
Identity Management functions
There are a number of Identity Management functions you can use to configure the default settings of your login/registration screens and control the behavior of Identity Management templates. They include:
|
|
This function allows you to configure Identity Management's default settings. Available settings are discussed below. |
|
|
This function triggers any Identity Management screen you want to show. The screen shown depends on how the |
|
|
This function triggers a Custom form.* |
|
|
This function makes the user logout. It is typically used to create a logout button for logged in users. You can pass in a callback as a parameter if you would like an event to occur following the logout. If the checkout is single-step or passwordless, the user is redirected back to the offer after logout. |
|
|
This function returns |
|
|
This function returns a current user's custom field. Once received, the user profile data will be passed via the |
|
|
This function returns the user's language. For example if the language is set to American English, the response would be |
*The format would look like this tp.pianoId.showForm({formName: 'formName', templateId: 'templateId', variantId: 'variantId'}), where you would insert the form_id of the custom form as the value for the formName, the Piano ID Custom Form template ID as the value for the templateId and if available, a variant ID of this template as the variantId.
The tp.pianoId.init() function allows you to override several default Identity Management parameters while the tp.pianoId.show() function allows you to trigger various Identity Management behaviors. The parameters for these functions include:
Parameter
|
Description
|
|
|
The url of the Identity Management deployment host. You need to change this parameter only if you have configured a dedicated domain for SSO support with Piano or you are using an app on the EU dashboard, where the URL would be https://id-eu.piano.io, the AP dashboard, where the URL would be https://id-ap.piano.io, or the AU dashboard, where the URL would be https://id-au.piano.io.* |
|
|
If this parameter is set to |
|
|
This token is created when a user wants to perform a password reset. This parameter is typically used with the |
|
|
The display mode of the Identity Management templates. The default value is |
|
|
Specify the Identity Management screen to show. Possible values include |
|
|
If you're using an inline template, this is the container selector. |
|
|
The width of |
|
|
The height of |
|
|
This callback is fired when a user logs in. |
|
|
This callback is fired when a user logs out. |
|
|
This callback is fired when a user successfully logs in. |
|
|
This callback is fired when a user successfully signs up a new account. |
|
|
This callback is fired when a user updates their profile via My Account as well as when a user profile is updated during a custom form submission. |
|
|
This callback is fired when a user changes their default language. |
|
|
This callback is fired when the login screen is presented. |
|
|
This callback is fired when the registration screen is presented. |
|
|
This callback is fired upon an unsuccessful login attempt. |
|
|
This callback is fired upon an unsuccessful registration attempt. |
*For example like this:
tp.push(["init", function () {
tp.pianoId.init({
iframeUrl:"https://id-eu.piano.io"
});
tp.experience.init()
}]);
Here's what a configured version of tp.pianoId.init() might look like:
tp = window.tp || [];
tp.push(['setUsePianoIdUserProvider', true]);
tp.push(["init", function() {
tp.pianoId.init({
displayMode: 'inline',
containerSelector: '#login-form',
loggedIn: function(data) {
console.log('user ', data.user, ' logged in with token', data.token);
},
loggedOut: function() {
console.log('user logged out');
}
});
}]);
And here's what a configured version of tp.pianoId.show() might look like:
tp = window.tp || [];
tp.push(['setUsePianoIdUserProvider', true]);
tp.push(["init", function() {
tp.pianoId.show({
disableSignUp: true,
displayMode: 'inline',
screen: 'login',
containerSelector: '#login-form',
loggedIn: function(data) {
console.log('user ', data.user, ' logged in with token', data.token);
},
loggedOut: function() {
console.log('user logged out');
}
});
}]);
To get custom field data from a logged-in user:
-
Create a custom form.
-
Add the required fields in the custom form.
-
Use the
form_nameparameter in the call toloadExtendedUser.
tp = window.tp || [];
tp.pianoId.loadExtendedUser({
extendedUserLoaded: function (data) {
for (var i in data.custom_field_values) {
var fieldName = data.custom_field_values[i].field_name;
var fieldValue = data.custom_field_values[i].value;
console.log("Field " + fieldName + " has value " + fieldValue);
}
}, formName: 'new_form'
});
Identity Management password reset JavaScript
You will need to add this JavaScript to the password reset landing page in order for the password reset template to appear when a user clicks a link within a password reset email:
tp.push(['init', function() {
// Password can be reset only if user is anonymous
if (!tp.user.isUserValid()) {
// If URL has reset_token parameter
var tokenMatch = location.search.match(/reset_token=([A-Za-z0-9]+)/);
if (tokenMatch) {
// Get value of the token
var token = tokenMatch[1];
// Present password reset form with the found token
tp.pianoId.show({
'resetPasswordToken': token, loggedIn: function () {
// Once user logs in - refresh the page
location.reload();
}
});
}
}
}]);