Using JQuery Terminal how do I setup an authentication routine that uses a javascript (not php) function?

StackOverflow https://stackoverflow.com/questions/17496364

Domanda

I'm working on a project where I use jQuery Terminal for a command line interface to functions.

I've been trying to use it's built in authentication capability, but want it to call a JavaScript function to obtain authentication and not calling PHP.

Do you happen to have an example of JQuery Terminal that calls a JavaScript authentication function, not a PHP function?

The documentation says:

You can provide your authentication function which will be called when user enter login and password. Function must have 3 arguments first is user name, second his password and third is callback function which must be called with token or null if user enter wrong user and password.

Been trying to get it to work without much luck....

jQuery(document).ready(function($) 
{ 
    var userName = ""; 
    var password = ""; 

    $('#term_demo').terminal(
            test1(
                userName,
                password,
                callbackFunction1() {
                    alert("Your login is incorrect");
                },
                {
                    login: true, 
                    greetings: "You are authenticated"
                }
            );        
    }); 

function test1(name1, password1, callbackFunction1)
{ 
    if(name1 == "Derek") 
    { 
        return true; 
    } 
    else 
    {
        return false;
    } 
}

function callbackFunction1() 
{ 
    alert("Invalid user name and password"); 
} 

Let me know if you have any suggestions or a simple example to get me going again...

È stato utile?

Soluzione

The first parameter of .terminal(...) is either a url to your rpc-service (string) or it is an object containing the commands you want to add (object).

The json-rpc implementation that is used does not need to be written in php. The rpc definitions are just a standardized way to provide a interface for remote procedure calls.

So if you don't want to use the rpc you would do something like this:

function test1(name, password, callback) 
{ 
    console.log("ok");

    if(name == "Derek") 
    {
        callback("some token");
    } 
    else 
    { 
        callback(false);
    } 
} 
jQuery(document).ready(function($) {
    $('body').terminal({}, {
        login: test1,
        greetings: "You are authenticated",
        onBlur: function() {
            // the height of the body is only 2 lines initialy
            return false;
        }
    });
});

The callback that is passed to the login function needs to be called, passing a token if login was successful, or false if not.

Normally you would to authentication server side, because everything that is in the browsers is not save. But because i don't know what you want to do with jquery.terminal i can't suggest you anything about this.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top