Klipfolio Dashboard 5 API

Object Engines.Login

Object
   |
   +--Klip
         |
         +--Engines
               |
               +--Engines.Login

Advanced Feature This object is only available in a licensed version of Klipfolio Dashboard. Contact Klipfolio for further details.

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()

getUsername

String getUsername()

initialize

function initialize( <String> buttonLabel, <String> loginPrompt, <String> userLabel, <String> passLabel, <String> dataPoolID, <String> loginHandler, <String> logoutHandler )

loginButtonClicked

function loginButtonClicked()

logout

function logout()

savePrefs

function savePrefs()

setError

function setError( <String> errorMessage )

showLoginButton

function showLoginButton( <boolean> visible )

toString

String toString()

Klipfolio Dashboard 5 API

© 2010 Klipfolio Inc. All Rights Reserved.