ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ion Auth - Lightweight Auth System based on Redux Auth 2

February 10, 2010 7:00pm

Subscribe [287]
  • #691 / Dec 23, 2010 8:01am

    kikz4life

    77 posts

    @chenda

    have u tried creating new user then login using it? im experiencing a problem when doing this. Hoping to hear your reply soon. thanks

  • #692 / Dec 23, 2010 8:07am

    ci_lover

    3 posts

    A solution for retrieving online users:

    Say I want to keep users logged in for 60 minutes (3600 secs):

    1- In global config.php (config/config.php):
    set the user session to last for 3600 secs:

    $config[‘sess_expiration’] = 3600;

    2- I then query the “users” table like this (using active record):

    function get_online_users(){
    $date = date("Y-m-d H:i:s", time());
    $users = $this->db
    ->where("TIMESTAMPDIFF(SECOND, FROM_UNIXTIME(last_login), '$date') < 3600")
    ->get('users');
    return $users->result_array();
    }

    This will return the users who logged-in in the last hour, and so, are considered online, problem solved 😊

    Hope this helps someone.

  • #693 / Dec 23, 2010 7:02pm

    Thinkers

    3 posts

    Hello Ben, hello everybody.
    I am creating my very first application with codeigniter and i am using this library for the simplicity and the power it has.

    Actually my login/register/forgot email procedures are protected by capthcas, and is good enough from the security side.
    But I know that captchas are really user-unfriendly and i like to get rid of them, so i was wondering if is there a method to prevent a flood of request to the module or is it planned at any stage in the library, or if someone know a method to present a captcha after x failure attempts.

    Anyone has already implemented one of these solutions?
    Thank you all.

  • #694 / Dec 28, 2010 6:46pm

    33cent

    26 posts

    Hi,

    i need one feature: emailing account info upon registration (example: accounts are created by admin, and users receive their login informations on email)

  • #695 / Dec 31, 2010 4:09pm

    Mantra of Doom

    21 posts

    Hi, I have more of a general question. I need to fetch a user’s data by the username.

    I get that I need to use get_user($id) to get the user data array, but I’m having trouble getting the id. I know I’m making a simple mistake, but I’m still not sure where. Any help would be appreciated.

    function get_player($username){
            $this->db->select('id');
            $this->db->where('username', $username); 
            $id = $this->db->get('users');
            
            $user = $this->ion_auth_model->get_user($id);  
            
        }

    this is the error I’m getting

    A PHP Error was encountered
    
    Severity: 4096
    
    Message: Object of class CI_DB_mysql_result could not be converted to string
    
    Filename: database/DB_active_rec.php
    
    Line Number: 453
    A Database Error Occurred
    
    Error Number: 1064
    
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 6
    
    SELECT `users`.*, `groups`.`name` AS `group`, `groups`.`description` AS `group_description`, `meta`.`location`, `meta`.`time_zone`, `meta`.`fav_games`, `meta`.`bio` FROM (`users`) LEFT JOIN `meta` ON `users`.`id` = `meta`.`user_id` LEFT JOIN `groups` ON `users`.`group_id` = `groups`.`id` WHERE `users`.`id` = LIMIT 1
  • #696 / Dec 31, 2010 4:28pm

    pickupman

    1317 posts

    I am guessing you are passing a blank $id. The query statement is breaking because it should not be users.id = LIMIT 1

  • #697 / Dec 31, 2010 10:56pm

    Mantra of Doom

    21 posts

    Pickupman: Yes, after looking at it again, I am passing a blank id.

    What I’m trying to do is at the user list, make the username a link to the user’s profile. The url should look like http://www.site.com/player/view/username

    What would the best way to do this?

    Here is my controller:

    // Show Player List 
        function player_list(){
            $this->load->model('player_model');
            $data = $this->player_model->general();
            $data['websubtitle']    = 'Player List';
            $data['users'] = $this->ion_auth->get_users_array();
            $data['content'] = 'player/player_list.php';
            $this->load->view('template', $data);
        }
        
    // Show the player's page 
        public function view($username=""){
        
            $this->load->model('player_model');
            $data = $this->player_model->general();
            $data['now'] = time();
            $data['username'] = $this->uri->segment(3); //I believe this is where it is breaking, but I can't figure a way to pass this info
            if($username = ""){
                $this->player_model->get_player($username);
                $data['websubtitle']    = 'View Profile';
                $data['content'] = 'player/view_profile';
                $this->load->view('template', $data);
                
            }    
            else{
                redirect('player/not_working'); //currently, I keep getting redirected to this page.
            }
        }
        // If the view doesn't work, send me to this page of sadness
        function not_working(){
                    $this->load->model('player_model');
            $data = $this->player_model->general();
            $data['websubtitle']    = 'Error';
            $data['content'] = 'player/error';
            $this->load->view('template', $data);
        }

    Model:

    // Gets a player's data for profile page
        function get_player($username){
            $this->db->select('id');
            $this->db->where('username', $username); 
            $id = $this->db->get('users');
            
            $user = $this->ion_auth_model->get_user($id);  
            
        }

    Player List view prints the user data into a table:

    <h3>All Players</h3>
    <p>    <br />
        <table><br />
            <tr><br />
                <th colspan=2>Player Name</th><br />
                <th>Member Since</th><br />
                <th>PM Player</th><br />
            </tr><br />
            <?php foreach ($users as $user):?><br />
                <tr><br />
                    <td><?php echo base_url();?>public/uploads/avatars/<?php echo $user[</td><br />
                    <td><?php echo anchor('player/view/'.$user['username'], humanize($user['username']));?></td><br />
                    <td><?php echo unix_to_human($user['created_on'], FALSE, 'us');?></td><br />
                    <td>Send PM</td><br />
                </tr><br />
            <?php endforeach;?><br />
        </table>

    I haven’t posted the player profile view because the above code never loads the profile page to begin with. I’ve been scratching my head over this for a week. Ion Auth is the easiest (for a beginner like me) auth library I’ve tried so far, and if I can get this profile page working, I’ll be all set to finish my project.

  • #698 / Dec 31, 2010 11:33pm

    pickupman

    1317 posts

    You could add this to ion_model.php

    /**
    * get_user_by_field
    *
    * @param string field name to search
    * @param string value to lookup
    *
    * @return object
    **/
    public function get_user_by_field($field, $value)
    {
       $this->db->where($this->tables['users'].'.'.$field, $value);
       $this->db->or_where($this->tables['meta'].'.'.$field, $value);
       $this->db->limit(1);
    
       return $this->get_users();
    }

    Then when you are iterating results for your links, you could use something like:

    $this->ion_auth->get_user_by_field('username',$username);

    Passing a parameter to your method and using the code below is redundant. It won’t break, but it’s doing the same thing:

    $data['username'] = $this->uri->segment(3);
    //same as
    $data['username'] = $username; //Since your are passing $username as a parameter
  • #699 / Jan 01, 2011 12:05am

    AndrewTurner

    16 posts

    Is it possible for users to have membership in multiple groups?

  • #700 / Jan 01, 2011 11:25pm

    Ben Edmunds

    812 posts

    AndrewTurner,

    Not yet but it is in the plans.

  • #701 / Jan 01, 2011 11:28pm

    Ben Edmunds

    812 posts

    Mantra of Doom,

    You already have the user id when you get_users_array so why not build your link with the ID instead of the username and just display the username?

    Or if the username is your identity you can use $this->ion_auth->profile($username) to get most of the user’s info.

  • #702 / Jan 02, 2011 11:04am

    Mantra of Doom

    21 posts

    I got it working now, thanks guys. Basically, my problem boiled down to the fact that I get confused when getting results out of an array. Thanks for all the help, I’m learning a lot by reading this thread.

  • #703 / Jan 03, 2011 12:36am

    marsd

    1 posts

    I’ve got 3 questions:

    I am wondering if I could extend your auth model and overwrite some of the functions in there to add more customisability for example allowing each user to have multiple nicknames/aliases using an associative table.

    If so, how should I do it as I’m reluctant to edit the model then find out later that an update would require me to re-do all the changes again.

    Also on the database side for multiple group memberships, are you going to redesign the DB with associative tables and relationships? If you are, will you also provide upgrade codes to migrate the existing group id info from the users to the associative table?

    Thanks

  • #704 / Jan 04, 2011 3:54pm

    Glazz

    170 posts

    Hello,

    I’ve installed ion auth yesterday, and it was working good, without any errors, today when i went to localhost to work on the website i get these two errors
    http://awesomescreenshot.com/0b55h4ra7

    These errors only show up once per session, don’t know why =\

    The only thing i have modified was table names, all the 3, the controller name and the view name, but it was working without any errors.

    Using CI 2


    Thanks!

    Edit:

    Some debug info:

    DEBUG - 2011-01-04 21:01:20—> Config Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Hooks Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Unicode Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Unicode Class - UTF-8 Support Enabled
    DEBUG - 2011-01-04 21:01:20—> URI Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Router Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Output Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Input Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Global POST and COOKIE data sanitized
    DEBUG - 2011-01-04 21:01:20—> Language Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Loader Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Helper loaded: url_helper
    DEBUG - 2011-01-04 21:01:20—> Helper loaded: byte_convert_helper
    DEBUG - 2011-01-04 21:01:20—> Helper loaded: form_helper
    DEBUG - 2011-01-04 21:01:20—> Language file loaded: language/english/fusephase_lang.php
    DEBUG - 2011-01-04 21:01:20—> Database Driver Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Session Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Helper loaded: string_helper
    DEBUG - 2011-01-04 21:01:20—> A session cookie was not found.
    DEBUG - 2011-01-04 21:01:20—> Session routines successfully run
    DEBUG - 2011-01-04 21:01:20—> Whois Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Session class already loaded. Second attempt ignored.
    DEBUG - 2011-01-04 21:01:20—> Cart Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Form Validation Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Config file loaded: site/config/ion_auth.php
    DEBUG - 2011-01-04 21:01:20—> Email Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Session class already loaded. Second attempt ignored.
    DEBUG - 2011-01-04 21:01:20—> Language file loaded: language/english/ion_auth_lang.php
    DEBUG - 2011-01-04 21:01:20—> Model Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Model Class Initialized
    DEBUG - 2011-01-04 21:01:20—> Helper loaded: cookie_helper
    DEBUG - 2011-01-04 21:01:20—> Helper loaded: date_helper
    DEBUG - 2011-01-04 21:01:20—> Session class already loaded. Second attempt ignored.
    ERROR - 2011-01-04 21:01:20—> Severity: Notice —> Undefined property: Alojamento::$ion_auth E:\Web\www\projectos\Fusephase_v2\sistema\core\Model.php 50
    ERROR - 2011-01-04 21:01:20—> Severity: Notice —> Undefined property: Alojamento::$ion_auth E:\Web\www\projectos\Fusephase_v2\sistema\core\Model.php 50

    DEBUG - 2011-01-04 21:01:20—> Controller Class Initialized
    DEBUG - 2011-01-04 21:01:20—> File loaded: site/views/topo.php
    DEBUG - 2011-01-04 21:01:20—> File loaded: site/views/footer.php
    DEBUG - 2011-01-04 21:01:20—> File loaded: site/views/alojamento/basico.php
    DEBUG - 2011-01-04 21:01:20—> Final output sent to browser
    DEBUG - 2011-01-04 21:01:20—> Total execution time: 0.0913

  • #705 / Jan 04, 2011 4:08pm

    joytopia

    76 posts

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases