PDA

View Full Version : Any examples of using ext.direct with server-side user authentication?



bareflix
25 Apr 2010, 10:49 AM
I've just set up extjs 3.2.0 with the ext-direct-php-1.01 server-side code.

I want to have the router return a 403 error for any api call if the user is not logged in. I'm planning to use a session cookie to track logins as with non-ajax apps, so the cookie could disappear at any time.

Given that the ext.direct functions only have 1 callback regardless of the results, is there any good way to catch the 403 error, show the login, process it, then execute the original request?

I saw an older example for the AJAX operations that did this as an extension. Is that possible with ext.direct?
If you know of any other pointers or examples, please let me know.

It seems like almost everyone will need to do this, so I hope it gets added to the core code someday.

--
Chris Bare

nekufa
26 Apr 2010, 10:33 PM
Ext.direct.RemotingProvider has event "exception".
You can add event handler to display login form.
On server you can throw an exception.

Sesshomurai
22 May 2010, 1:27 PM
Yes, you can catch exceptions. This is how I do it. Then you can read the exception string and show messages, redirect or do something else.



Ext.Direct.on('exception', function(e) {
// check exception info
// alert user to login, redirect
// log error
// etc. etc.
});


Works great for me.

xp743
4 Jun 2010, 3:15 AM
just simple authentication when request sent by client : isset($_SESSION['authuid'])

when client not loged in than all request data will have same result for call login module : array('success'=>'false','callback'=>'SITTK.Main.setLogout();')

on our js script we declare for callback function :


ExtAction.get('auth',function(result){eval(result.callback)})


function doRpc($cdata){
global $API;
try {
if(!isset($API[$cdata->action])){
throw new Exception('Call to undefined action: ' . $cdata->action);
}

$action = $cdata->action;
$a = $API[$action];

doAroundCalls($a['before'], $cdata);

$method = $cdata->method;
$mdef = $a['methods'][$method];
if(!$mdef){
throw new Exception("Call to undefined method: $method on action $action");
}
doAroundCalls($mdef['before'], $cdata);
if($cdata->type == 'rpc'){
$r = array(
'type'=>'rpc',
'tid'=>$cdata->tid//,
//'action'=>$action,
//'method'=>$method
);
}else{
$r = array();
}
require_once("controllers/$action.php");

$o = new $action();
$params = isset($cdata->data) && is_array($cdata->data) ? $cdata->data : array();
$r['result'] = isset($_SESSION['authuid']) ? call_user_func_array(array($o, $method), $params) : array('success'=>'false','callback'=>'SITTK.Main.setLogout();');
}
doAroundCalls($mdef['after'], $cdata, $r);
doAroundCalls($a['after'], $cdata, $r);
}