Raxan Plugin: Auth

A place to share your Plugins and Extensions

Raxan Plugin: Auth

Postby fc_Damir » Fri Dec 10, 2010 1:22 pm

Hi,

I want to share with all raxan community authentication raxan plugin.

With this plugin you can simple protect your page with login, or manage user, group and permission page by page
and store user session to database (so you can have statistics of logged user and how mouch user is online).

This is the first realese and I will add more features ASAP.

in the zip folder there is also the 6 database tables:

- users
- user_logins
- groups
- permissions
- pages
- user_sessions

Example of usage:

For protect page (check if user can have permission to view page):
Code: Select all
$this->auth->isAuthorize($this->activeView)


For check login form:
Code: Select all
$this->auth->check($this->post->username, $this->post->password)


Logooff:
Code: Select all
$this->auth->logoff()


Restore password:
Code: Select all
$this->auth->restorepassword($this->post->email)


Create account:
Code: Select all
$this->auth->createaccount($data)


Check if logged:
Code: Select all
$this->auth->isLogged()


Have fun
Attachments
RaxanPluginAuth.zip
v0.1
(3.71 KiB) Downloaded 258 times
Last edited by fc_Damir on Fri Dec 10, 2010 2:46 pm, edited 1 time in total.
fc_Damir
 
Posts: 33
Joined: Mon Jun 14, 2010 9:13 am

Re: Raxan Plugin: Auth

Postby raymond » Fri Dec 10, 2010 2:11 pm

Hi Damir,

I've dowloaded the plugin and it's looking great. I see that you have packed a lot of features into this one :)

Many thanks for sharing

Just a few things that you can do with RC1:

1. It's now possible to get an instance of the loaded plugin:
Code: Select all
    $this->auth = $this->loadPlugin('auth');
    $this->auth->init($this->db);
    // or
    $this->loadPlugin('auth', 'auth'); // loads plugin and assign instance to $this->auth
    $this->auth->init($this->db);


For the above to work you will have to first register the plugin using Auth::register(). See http://raxanpdi.com/sdk/docs/plugins.html.

__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: Raxan Plugin: Auth

Postby fc_Damir » Fri Dec 10, 2010 3:35 pm

Thanks for suggestion.
I add to config file auth plugin, so it will automatic load.
Code: Select all
$config['preload.plugins'] = 'auth';


and just add this to the page:
Code: Select all
$this->auth = new Auth();
$this->auth->init($this->db)
;

In this way is also simple (two line of code)

Regards
fc_Damir
 
Posts: 33
Joined: Mon Jun 14, 2010 9:13 am

Re: Raxan Plugin: Auth

Postby fc_Andrea » Sat Mar 05, 2011 11:15 pm

Hi,
I downloaded the packed solution but I can't find reference to the table structure..How can I do?
Thanx in advance.
Andrea
fc_Andrea
 
Posts: 1
Joined: Sat Mar 05, 2011 11:13 pm

Re: Raxan Plugin: Auth

Postby fc_Damir » Sun Mar 06, 2011 5:59 pm

Hi Andrea,

Sorry for inconvenience.

Here is full package with db.sql file for creation database structure.
RaxanPluginAuth.zip
(4.22 KiB) Downloaded 197 times


I work on a new version of auth plugin, that is more simple, by using bitmask permission for access and action.

Here is the version 2
auth-plugin-v2.zip
(5.36 KiB) Downloaded 196 times


I need a few days to prepare the documentation for this plugin.

Best regards
Damir
fc_Damir
 
Posts: 33
Joined: Mon Jun 14, 2010 9:13 am

Re: Raxan Plugin: Auth

Postby noviandi_pakuan » Thu Jun 16, 2011 11:56 am

dear damir and all,

i already try auth-plugin-v2 but it seem there is problem in my code when i use it, i'll already put the auth.php in raxan plugins folder and here my piece of code :
Code: Select all
    protected function _config(){
   $this->autoAppendView = true;
        $this->preserveFormContent = true;
        $this->degradable = true;
        $this->masterTemplate = 'views/header1.php';
      $this->icon = '<span title="Close" class="right close ui-icon ui-icon-close click-cursor"></span>';
      $this->auth = $this->loadPlugin('auth');
    }
   
    protected function _init() {
      try {
         $this->db = $this->Raxan->connect('gallery');
         
         $data = $this->db->execQuery('select groupid,groupname,images,ket,style from grp order by groupname');
         $this->bag->bind($data);
         $this->auth->init($this->db);
      }
      catch(Exception $e){
          $this->flashmsg($this->icon.'unable connect to database','fade','rax-box error');
      }
   }

        protected function register() {    // event callback
      $data = $this->post->filterValues('lastname,firstname,email,username,password,birth,religion,gender,marital');
      
      /*foreach($data as $k => $v){          // checking if data is empty, but is not the data are OK
         $msg .=  $k .' ' . $v;
      }
      $this->flashmsg($msg,'fade','rax-box notice');*/
      
      if ($this->auth->createAccount($data)){         
         $this->flashmsg($this->icon.'Your account has been created, activated by visiting your email','fade','rax-box error');
         
         $err = $this->post->fileUploadError('file1');
         if ($err) {
            $errors = array(
               0=>"There is no error, the file uploaded with success",
               1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
               2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
               3=>"The uploaded file was only partially uploaded",
               4=>"No file was uploaded",
               6=>"Missing a temporary folder"
            );
            $this->flashmsg($errors[$err],'fade','rax-box notice');
            return;
         }
         
         if (substr($this->post->fileType('profil'),0,5) == 'image'){
              $this->post->fileImageResample('profil',350,300,'jpeg');
            try {
               $imgFile = dirname(__FILE__).'\profil\sample.jpg'; // make sure file is writable
               $this->post->fileMove('profil',$imgFile);
               
               $path = dirname(__FILE__). '\profil\\' .$this->post->textVal("username").'__'.$this->post->fileOrigName('profil');

               Copy($imgFile,$path);
               $sql = "update users set profil = '".$this->post->textVal("username")."__".$this->post->fileOrigName('profil')."' where username = '".$this->post->textVal("username")."'";
               $ft = $this->db->query($sql);
               
               if (!$ft){
                  $this->flashmsg($this->icon.'Your profil account failed upload','fade','rax-box error');
               }
            }catch (Exception $err) {
               $msg = 'Unable to process image file. Make sure data/sample.jpg is writable.';
               $this->flashmsg($msg,'fade','pad softred');
            }
         }else{
            $this->flashmsg($this->icon.'Your profil picture are not supported','fade','rax-box error');
         }
      }else{
         $this->flashmsg($this->icon.'failed: '.$this->auth->getMessage(),'fade','rax-box error');
      }
   }


the problem is when i call $this->auth->createAccount($data) the data that i sent to auth is empty,
i check by using $this->auth->getMessage()

it alway's failed

please your guide and suggest if something wrong with my code

best regards
noviandi
noviandi_pakuan
 
Posts: 41
Joined: Mon Nov 01, 2010 2:50 am

Re: Raxan Plugin: Auth

Postby fc_Damir » Fri Jun 17, 2011 10:48 am

Hi,

The createaccount method is this:
Code: Select all
public function createAccount($post){

          $data = array(
            "last_name"  => $post["last_name"],
            "first_name" => $post["first_name"],
            "email"      => $post["email"],
            "nickname"   => $post["nickname"],
            "password"   => md5($post["password"]),
            "group_id_fk"     => 2000000,
            "status"     => "not confirmed"
            );
.....
         }



the key of post must be last_name, first_name, email, nickname, password

you use $data = $this->post->filterValues('lastname,firstname,email,username,password,birth,religion,gender,marital');

Are you change createaccount method?

if not change this like this:

Code: Select all
          $data = array(
            "last_name"  => $post["lastname"],
            "first_name" => $post["firstname"],
            "email"      => $post["email"],
            "nickname"   => $post["username"],
            "password"   => md5($post["password"]),
            "group_id_fk"     => 2000000,
            "status"     => "not confirmed",

// add here birth, religion, gender, marital



            );



Let me know if this solve issue.

Best regards,
Damir
fc_Damir
 
Posts: 33
Joined: Mon Jun 14, 2010 9:13 am

Re: Raxan Plugin: Auth

Postby noviandi_pakuan » Fri Jun 17, 2011 3:10 pm

dear damir,

here is structure of the database that you givent on plugins
-- Table structure for table `users`
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL auto_increment,
`group_id` int(11) NOT NULL,
`firstname` varchar(32) NOT NULL,
`lastname` varchar(32) NOT NULL,
`username` varchar(16) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(320) NOT NULL,
`profile` longblob,
`country_iso` varchar(4) default NULL,
`status` enum('not confirmed','active','inactive','deleted') NOT NULL default 'not confirmed',
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

sory for ask, is it ok if the plugins sent the key that aren't same with the database fields ..?
$data = array(
"last_name" => $post["last_name"],
"first_name" => $post["first_name"],
"email" => $post["email"],
"nickname" => $post["nickname"],
"password" => md5($post["password"]),
"group_id_fk" => 2000000,
"status" => "not confirmed"
);

if($this->db->table($this->tbl_prefix."users user_id_pk", "user_email=? or user_nickname=?", $data["email"], $data["nickname"])) ....

if($this->db->tableInsert($this->tbl_prefix."users", $data)).....


i already change the plugins code so it's fit with the database that you given, but when i sent array to the plugins the data alway's empty when received by plugins but when i test on procedure the data is OK....

best regard
noviandi
noviandi_pakuan
 
Posts: 41
Joined: Mon Nov 01, 2010 2:50 am

Re: Raxan Plugin: Auth

Postby noviandi_pakuan » Wed Jun 22, 2011 6:16 am

Dear Damir,

It's work, i remark the mail function to non active, it seem the mail hasn't setting properly, but it's great plugins

lot of thank for guide

best regard
noviandi.
noviandi_pakuan
 
Posts: 41
Joined: Mon Nov 01, 2010 2:50 am


Return to Plugins & Widgets

Who is online

Users browsing this forum: No registered users and 1 guest

cron