Using Piano accounts

If your app is configured for Piano Accounts, then additional login / logout functions are available.

Login

To allow a user to perform a standalone login, the following method should be called. This method accepts a loginSuccess callback to listen for successful logins.

  tp.user.showLogin({
    loginSuccess:function() { doSometingOnSuccess() } 
  });
 

Please note that some modern browsers will prevent login popups from opening if the call for this function does not originate from a users' input. This means that you can only assign it to a click event, and cannot execute it automatically after the page loads.

Sign up

To create a sign up popup - the method is the same, but it accepts additional parameter “state”. This method accepts a loginSuccess callback to listen for successful logins.

  tp.user.showLogin({
    state: 'register',  
    loginSuccess:function() { doSometingOnSuccess() } 
  });
 

Checking if a user is logged in

To check if user logged in, use the following function:

tp.user.isUserValid();

Note that this function, as any other, will only be available after the initialization of the javascript library. To check if user is logged in on a page load - use the following code:

tp.push(["init", function(){
    if (tp.user.isUserValid()){
        // Show "Logout" button
    }
    else{
        // Show "Login" button
    }
}]);

Logout

To allow a user to logout

  tp.user.logout( doSomethingOnLogout() );