Now, in previous posts i explained how to add the “before Filter” functionality but roles filtering was not very clear nor explained, in this post i will guide you in such task. In this current version of AMFPHP (May 20th 2007) there is no a defined function or method on how to handle roles, but with a little workaround you will find them useful. Yep as i said workaround due to it is a beta release i am not sure if Patrick will change or add a method to handle roles, to sum up previous posts:
- method table disappeared
- “_” is requiered to set “private” functions or simply use private function(){}
- roles needed to be encountered (maybe not till now)
I also mentioned that if you write comments just before the function itself those comments are like the “old methodTable” and you will see what i mean, first create your document (class document):
class asb_labs{
/**
*here set variables with the name of your functions just as the old methodTable with the *only difference that these ones just contains roles
*
*/
var $methodOne="admin,normal,registered,user,super";
var $methodTwo="admin,super";
function asb_labs(){
/**
*the constructor is useful when you are opening your database, you can open a
*persistent connection
*/
$this->conn = mysql_pconnect("localhost","user", "password");
mysql_select_db ("db");
}
/**
*this is the new way to write your method's description
*
*@param $str(String) here you define your param datatype
*@param $str2(strin) another param
*/
function methodOne($str,$str2){
return "look this is method one!!";
}
/**
*description here
*/
function methodTwo(){
return "look this is method two!!";
}
/**
*now to let AMFPHP detect the method being called use this function
*/
function beforeFilter($function_called){
/*we want login() and logout() be accessed now matter if the user is or isn´t validated*/
if($function_called=="login" || $function_called=="logout"){
return true;/** when returning true means it can be executed*/
} else {
/**
here comes our part
*/
$permi=$this->$function_called;
eval("$permi = \"$permi\";");
/** here AMFPHP compares again the allowed roles*/
return Authenticate::isUserInRole($permi);
/** isUserInRole() is a built-in method as well as Authenticate::login and Authenticate::logout*/
}
function login($usr,$pwd){
/**
here you should log your user and register it(s) roles, (supposing we did a mysql query)
*/
Authenticate::login($usr,$rol);/** the $rol param can be a list of rols separated by comma, in this example let's assign it "user,registered"*/
return true;/** returning true means the user logged succesfully otherwise deny access*/
}
function logout(){
Authenticate::logout();
/**
logs the user out
*/
}
}
and that’s it is all, now you can have several rols for your methods and several rols for your users in an easy way to manage and mantain your code, enjoy and if you have any further comments just go on!!













Hola, bienvenido al area un tanto informal de nuestro sitio, donde conversamos de lo que sucede con la tecnología flash, conlusions.....before getting the products :)