Welcome Guest, Not a member yet? Register   Sign In
ErkanaAuth: A non-invasive user authentication library
#51

[eluser]xwero[/eluser]
great work tomcode a perfect compagnion for the library.
#52

[eluser]Neovive[/eluser]
Michael: This looks great! I downloaded the library from your website, but it appears to be the older version. Is the newly revised "3 method only" version available?
#53

[eluser]benlm[/eluser]
Does anyone have a version of the erkana library with the changes/fixes listed in this thread?

The library looks good in terms of size and scope, however one thing I don't like is the name of the helper functions getField and getRole. I think they should be renamed to be something like erkana_getField/erkana_getRole or userGetField/userGetRole.
#54

[eluser]tomcode[/eluser]
[quote author="benlm" date="1200117851"]Does anyone have a version of the erkana library with the changes/fixes listed in this thread?[quote]

There is a version of imzyos on the Wiki.
#55

[eluser]BrandonDurham[/eluser]
How do I go about encrypting my cookies for ErkanaAuth?
#56

[eluser]tomcode[/eluser]
You can encrypt Your cookies by setting the corresponding value in application/config/config.php.
#57

[eluser]BrandonDurham[/eluser]
Ah! Simple, thank you.
#58

[eluser]Michael Wales[/eluser]
I've had a few requests for the most recent version of ErkanaAuth (the one including the changes listed here in this thread). Well, it doesn't exist, unfortunately.

What I do have is the version of ErkanaAuth that I use within all of my development. I'm down to 3 methods and none of the User Management stuff (roles and such). Here, it is - in all it's glory, with some examples to follow.

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Auth {

    var $CI;
    
    function __construct() {
        $this->CI =& get_instance();
        log_message('debug', 'Authorization class initialized.');
        
        $this->CI->load->database();
    }
    

    function try_login($condition = array()) {
        $this->CI->db->select('id');
        $query = $this->CI->db->getwhere('users', $condition, 1, 0);
        if ($query->num_rows != 1) {
            return FALSE;
        } else {
            $row = $query->row();
            $this->CI->session->set_userdata(array('user_id'=>$row->id));
            return TRUE;
        }
    }
    
    
     function logout() {
        $this->CI->session->set_userdata(array('user_id'=>FALSE));
    }
    
    
    function get_user($id) {
        if ($id) {
            $query = $this->CI->db->getwhere('users', array('users.id'=>$id), 1, 0);
            if ($query->num_rows() == 1) {
                return $query->row();
            } else {
                return FALSE;
            }
        } else {
            return FALSE;
        }
    }
}

?>


How I Use It
logout() is still used the same way - a direct call within a controller, then redirect somewhere.

I still use try_login() the same way as well - within a callback function

get_user() is a bit different than what we've seen in the past. I usually extend my Controller class, having all of my classes assign the return value to a variable I can us within my view (for echoing out user info, as needed). For any controllers needing Authorization - I make a valid get_user() return value a requirement.

application/libraries/MY_Controller.php
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Public_Controller extends CI_Controller {
    function Public_Controller() {
        parent::Controller();
        $this->data->user = get_user($this->session->userdata('user_id'));
    }
}

class Admin_Controller extends Public_Controller {
    function Admin_Controller() {
        parent::Controller();
        if ($this->data->user === FALSE) {
            redirect('user/login');
            return;
        }
    }
}
#59

[eluser]tomcode[/eluser]
I just wonder why You implement it as library and not as model.
#60

[eluser]Michael Wales[/eluser]
Because to me, models define data. This has very little to do with data and a lot to do with business logic.

A model, for users, would display what fields define a user and the methods used to do things like: create a new user, delete a user, etc.




Theme © iAndrew 2016 - Forum software by © MyBB