|
@crow
i will look at CB next week
@stone
u will make instructions to create own modules
this is a little howto:
1. create own class, called like you module ( and class name )
2. each module must have functions called: login/logout/userget/userset/getcookies
example.class.php
[php]
// this parameter will be used for module administrations // left is params value, right is a name in the admincp
$params=array( 'dbhost' => 'Database Host', 'dbuser' => 'Database User', 'dbpass' => 'Database Pass', 'dbname' => 'Database Name', 'prefix' => 'Database Prefix', 'cookie' => 'Cookie Prefix');
class example extends mosMainFrame { // connection ressource var $__res= null; // gives the status of the module var $__status= false; // contains module informations var $__data; // class contains user information, must be a class!! var $__userdata=null; // not used at the moment var $__sessionid=null;
// AS module you will get params class from mosParameters, id is a ID from the component // in this functions you can make soap/xmlrpc or database connects function example ($module,$id='') { $this->__data = $module;
$this->__res = new database( $this->__data->get('dbhost'), $this->__data->get('dbuser'), $this->__data->get('dbpass'), $this->__data->get('dbname'), $this->__data->get('prefix'), false );
if(is_resource($this->__res->_resource)) { $this->__status=true; } else { $this->__status=false; $this->__res=null; }
return $this->__status; }
// function to login a user // returns true ore fals // !!! it must set a __userdata->userid variable with the userid, it is needed to userset function function login($username,$password) { if(is_null($this->__res)) { return $this->__status; }
// query to access user $query = "SELECT user_id AS userid, username, user_password, user_active, user_level FROM " . $this->__data->get('prefix') . "users WHERE username = '" . str_replace("\\'", "''", $username) . "' AND user_password='".md5($password)."' AND user_active=1 "; $this->__res->setQuery( $query ); if($this->__res->loadObject($userdata)) { $this->__userdata=$userdata; $this->__status=true; } else { $this->__status=false; } return $this->__status;
} // ths function will be called by transfer from the user to your application function activate() { if(is_null($this->__res)) { return $this->__status; }
return $this->__status;
} // this function must unset the cookie, that you have set or make other things that your application need to logout a user function logout() { $lifetime = time() - 1800; // cookies setzen setcookie( $this->__data->get('cookie')."userid", " ", $lifetime, "/" ); setcookie( $this->__data->get('cookie')."password", " ", $lifetime, "/" ); setcookie( $this->__data->get('cookie')."sessionhash", " ", $lifetime, "/" ); }
// function to set the user in your application function userset($username, $password, $email) { if(is_null($this->__res)) { return $this->__status; }
}
// function to get userdata from your application // variables __userdata->username, __userdata->name and __userdata->email must be present function userget($userid) {
if(is_null($this->__res)) { return $this->__status; }
$query="SELECT u.*, user_id AS userid FROM ".$this->__data->get('prefix')."users AS u WHERE userid='$userid' "; $this->__res->setQuery( $query ); if($this->__res->loadObject($userdata)) { $this->__userdata=$userdata; $this->__userdata->name=$userdata->username; $this->__status=true; } else { $this->__status=false; }
return $this->__status; }
// function to "set" cookie // all cookies will be set by the connector // you must give the cookies as array to the connector /* example:
array cookiename = array( 0 => cookievalue 1 => cookiepath 2 => cookiedomain ( can be empty but must be present ) )
*/
function getcookies() { // cookies setzen $cookies[$this->__data->get('cookie')."userid"] = array( $this->__userdata->userid, '/',''); $cookies[$this->__data->get('cookie')."password"] = array( md5($this->__userdata->password.$this->__data->get('license')), '/','');
// Session erstellen und als Cookie schreiben ### kommt noch ### return $cookies; }
}
?> [/php]
|