I wrote a login in sencha touch. Quite simple. A simple form with username and password. Submit a request to the server where I execute a sql to search the corresponding username/password. If a result is found then return success=true and the member_id and member_username.
It works in Chrome and also using Eclipse/Phonegap.
Now I expanded the sql so also the password is returned from the sql. In md5 it is stored in the db. So I can store this in the localstorage. For some reason the password I get back from the server is always "undefined". Although in Chrome it works fine. In Eclipse/Phonegap the value is "undefined".
Here is the code from the JSONP. The code "console.log(response.user.member_pw);" shows "undefined". Allthough in Chrome it is filled in correctly... With the md5 value of the password.
PHP Code:
Ext.util.JSONP.request({
url: 'http://10.0.2.2/mobile/login.php',
params: options.data,
callbackKey: "callback",
scope: this,
callback: function(response) {
console.log("checklogin success");
if (response.success == "true")
{
console.log("Paswoord returned:");
console.log(response.user.member_pw);
var member = Ext.ModelMgr.create({
member_id: response.user.member_id,
member_username: response.user.member_username,
member_password: response.user.member_pw
}, 'Login');
app.subapps.Login.stores.login.add(member);
app.subapps.Login.stores.login.sync();
this.index(options);
}
else {
Ext.Msg.alert('', response.errors.reason, '');
console.log("failure");
}
}
});
}
Here is the code from the login.php
PHP Code:
$username = $_GET['username'];
$pw = $_GET['password'];
$callback = $_REQUEST['callback'];
$sql_select = "select member_id, member_username, member_password from member where member_username like '".$username."' and member_password like '".md5($pw)."'";
$sql_result = mysql_query($sql_select, $db) or die ("Error: ".mysql_error());
$sql_number_records = mysql_num_rows($sql_result);
if ($sql_number_records == 1)
{
$sql_record = mysql_fetch_array($sql_result);
$idRef_user = $sql_record[0];
$member_username = $sql_record[1];
$member_pw = $sql_record[2];
$json_return = '{"success": "true", "user": { "member_id": "'.$idRef_user.'", "member_username": "'.$member_username.'", "member_pw": "'.$member_pw.'"}}';
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '(' . $json_return . ');';
} else {
header('Content-Type: application/x-json');
echo $json_return;
}
}
else
{
$json_return = '{"success": "false", "errors": { "reason": "Login failed"}}';
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '(' . $json_return . ');';
} else {
header('Content-Type: application/x-json');
echo $json_return;
}
}
}