The Engines.Login object provides convenient methods for setting up a login UI for a Klip, as shown below. It takes advantage of the functionality provided by Klipfolio Dashboard's Login extension and is especially useful when multiple Klips require the same login, eliminating the need to log in as often as there are Klips.
Example:
In the following example, entering any text in the Email and Password fields and clicking the login button will
load the content in the Klip. Note that the content source in this example does not actually require the user to log in
in order to view the data; therefore, the Klip does not include any functionality to log in to a server.
<?xml version="1.0" encoding="UTF-8" ?>
<klip>
<identity>
<title>
API: Engines.Login
</title>
<version>
1.0
</version>
</identity>
<locations>
<icon>
http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
</icon>
<banner>
http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png
</banner>
<contentsource>
http://rss.news.yahoo.com/rss/topstories
</contentsource>
</locations>
<setup>
<statusvisible>
false
</statusvisible>
</setup>
<klipscript>
<![CDATA[
var loginPool = "API_Engines_LOGIN";
Engines.load("Login");
// Perform these actions when the klip is initially loaded
function onLoad() {
// Display the "Log In" option in the Klip menu
setGlobalActions( false );
//Load the login engine that will give us the login window with the following parameters
Engines.Login.initialize ( "Log in", "Log in to read the headlines", "Email:", "Password:", loginPool, loginHandler, logout );
// Display the login button in the Klip
Engines.Login.showLoginButton ( true );
}
// This is a function that will be called by Login when the login button is pressed
function loginHandler ( user, pass )
{
var errorMessage = "";
// If the user and pass fields are blank, display an error message
if(!user.length | !pass.length)
{
errorMessage = "Please enter valid login information.";
Engines.Login.setError ( errorMessage );
return false;
}
Engines.Login.setError ("");
Engines.Data.process( Prefs.contentsource );
savePrefs();
traceln( "Remember me is: " + Prefs.getPref( "remember" ) );
// Display the "Log Out" option in Klip menu
setGlobalActions (true);
return true;
}
//Set the klip right click menu entries
function setGlobalActions (loggedIn)
{
var loginText = "Log In";
var loginFunction = Engines.Login.loginButtonClicked;
if (loggedIn)
{
loginText = "Log Out";
loginFunction = logout;
Items.globalactions = [loginText, loginFunction ];
}
else
{
// If not logged in, display the "Log In" option in the Klip menu and clear all items
Items.globalactions = [loginText, loginFunction];
Items.clear(true);
}
}
// Logout handler, also called by Login when another klip with the same ID logs out
function logout()
{
Engines.Login.logout ();
Engines.Login.savePrefs ();
Items.clear(true);
Items.Deleted.clear();
setGlobalActions (false);
}
//Perform these actions when the klip is refreshed
function onRefresh()
{
var user = Engines.Login.getUsername ();
var pass = Engines.Login.getPassword ();
var success = loginHandler (user, pass);
if (user.length)
{
Engines.Login.showLoginButton (false);
return success;
}
else
{
Engines.Login.showLoginButton (true);
}
return true;
}
// Save the preferences in the prefs.xml file in settings folder
function savePrefs()
{
//Save username, password depending on remember me setting
Engines.Login.savePrefs ();
}
]]>
</klipscript>
</klip>
Since:
5.3
| Function Summary | |
String
|
getPassword()
Gets the password stored in the Klip's preference. |
String
|
getUsername()
Gets the user name stored in the Klip's preference. |
function
|
initialize( <String> buttonLabel, <String> loginPrompt, <String> userLabel, <String> passLabel, <String> dataPoolID, <String> loginHandler, <String> logoutHandler )
Initializes the Login Engine with labels of all UI components, login and logout handlers that Klips implement, and a data pool ID for sharing the login information between the Klips. |
function
|
loginButtonClicked()
Opens the login window when the login button is clicked. |
function
|
logout()
Sends a logout request to the Login Engine and logs the user out of all Klips that are using it. |
function
|
savePrefs()
Saves the user name, password and whether or not the user selected "Remember me on this computer" to the Klip's preferences. |
function
|
setError( <String> errorMessage )
Sets an error text message on the login window. |
function
|
showLoginButton( <boolean> visible )
Specifies whether to display the login button in the Klip. |
String
|
toString()
Prints the login object. |
| Function Detail |
getPassword
String getPassword()
- Gets the password stored in the Klip's preference.
Since:
5.3
-
Returns:
-
the stored password
getUsername
String getUsername()
- Gets the user name stored in the Klip's preference.
Since:
5.3
-
Returns:
-
the stored user name
initialize
function initialize( <String> buttonLabel, <String> loginPrompt, <String> userLabel, <String> passLabel, <String> dataPoolID, <String> loginHandler, <String> logoutHandler )
- Initializes the Login Engine with labels of all UI components, login and logout handlers that Klips implement, and a data pool ID for
sharing the login information between the Klips.
Example:
function onLoad() {
...
// Load the Login Engine
Engines.Login.initialize ("Log in", "Log in to read the headlines",
"Email:", "Password:", loginPool, loginHandler, logout);
...
}
Since:
5.3
-
Parameters:
buttonLabel - the label to display in the login button in the Klip
loginPrompt - the label to display at the top of the login UI
userLabel - the label to display for the first text field, usually for the user name, in the login UI
passLabel - the label to display for the second text field, usually for the password, in the login UI
dataPoolID - the ID of the data pool in which login and logout information is stored and shared
loginHandler - the name of the login handler
logoutHandler - the name of the login handler
loginButtonClicked
function loginButtonClicked()
- Opens the login window when the login button is clicked.
Since:
5.3
logout
function logout()
- Sends a logout request to the Login Engine and logs the user out of all Klips that are using it.
Since:
5.3
savePrefs
function savePrefs()
- Saves the user name, password and whether or not the user selected "Remember me on this computer" to the Klip's preferences.
Since:
5.3
setError
function setError( <String> errorMessage )
- Sets an error text message on the login window.
Since:
5.3
-
Parameters:
errorMessage - text to display when the Login Engine encounters a login error
showLoginButton
function showLoginButton( <boolean> visible )
- Specifies whether to display the login button in the Klip. When it is set to true, the login button is displayed
with the label string specified as the first parameter for Engines.Login.initialize().
Since:
5.3
-
Parameters:
visible - true to display the login button; otherwise false
toString
String toString()
- Prints the login object.
Since:
5.3
|
Klipfolio Dashboard 5 API | ||||||||
| PREV OBJECT NEXT OBJECT | FRAMES NO FRAMES | ||||||||
| SUMMARY: PROPERTY | FUNCTION | DETAIL: PROPERTY | FUNCTION | ||||||||
© 2010 Klipfolio Inc. All Rights Reserved.
