WebOSDev - Programming has just evolved

The online blog for the webOS developer community you can find everything you need here to get a strong start developing applications for the webOS platform

Howto interact between a wordpress site and webos

Posted by codesos Saturday, January 9, 2010 0 comments


Evere wanted to login to a wordpress type of site? here it is







1. load a PHP file to your site called myLogin.php

This file will act as your server side and it's job is to get the request wfom you app , do the login operation and returnt status



write the folowings inside the php file:



<?php

require( dirname(__FILE__) . '/wp-load.php' );

function login() {

$result = wp_signon();

if(!$result->data)

return "<br />Incorrect username or password.";

else

return TRUE;

}

echo login();

?>




2. in your webos application create a scene:

The idea is to send the PHP file the request with parameters

create username and password widget , emit a buttun press for login and write this:



ComunityAssistant.prototype.AjaxLogin = function(user,pwd)

{

var url = '[your site]/SERVICE-login.php';

try {

var request = new Ajax.Request(url, {

method: 'post',

parameters: {log: user, pwd: pwd},

onSuccess: this.AjaxLoginOK.bind(this),

onFailure: this.AjaxLoginError.bind(this)

});

}

catch(e)

{

Mojo.Log.info('Failed to get Ajax response');

Mojo.Log.info(e);

}

}





ComunityAssistant.prototype.AjaxLoginOK = function(response)

{

try

{

if (response.responseText.search("Incorrect username or password") != -1)

{

// error

}

else

{

if (response.responseText.search("1") != -1)

{

// OK

}

}

}

catch(e)

{

Mojo.log.error(e);

}

}







ComunityAssistant.prototype.AjaxLoginError =function(transport)

{

var t = new Template($L("Error: Status #{status} returned from AJAX Google search."));

var m = t.evaluate(transport);

this.controller.showAlertDialog

(

{

onChoose: function(value) {},

title: $L("Error"),

message: m,

choices:[

{label: $L('OK'), value:'ok', type:'color'}

]

}

);

}





there you go!!