Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]kikz4life[/eluser]
@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

[eluser]ci_lover[/eluser]
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:iConfused", 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 Smile

Hope this helps someone.

[eluser]Thinkers[/eluser]
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.

[eluser]33cent[/eluser]
Hi,

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

[eluser]Mantra of Doom[/eluser]
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.

Code:
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
Code:
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

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

[eluser]Mantra of Doom[/eluser]
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 www.site.com/player/view/username

What would the best way to do this?

Here is my controller:
Code:
// 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:
Code:
// 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:
Code:
<h3>All Players</h3>
    
    <table>
        <tr>
            <th colspan=2>Player Name</th>
            <th>Member Since</th>
            <th>PM Player</th>
        </tr>
        &lt;?php foreach ($users as $user):?&gt;
            <tr>
                <td><img src="&lt;?php echo base_url();?&gt;public/uploads/avatars/&lt;?php echo $user['username']; ?&gt;.png" width="25" height="25"/></td>
                <td>&lt;?php echo anchor('player/view/'.$user['username'], humanize($user['username']));?&gt;</td>
                <td>&lt;?php echo unix_to_human($user['created_on'], FALSE, 'us');?&gt;</td>
                <td>Send PM</td>
            </tr>
        &lt;?php endforeach;?&gt;
    </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.

[eluser]pickupman[/eluser]
You could add this to ion_model.php
Code:
/**
* 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:
Code:
$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:
Code:
$data['username'] = $this->uri->segment(3);
//same as
$data['username'] = $username; //Since your are passing $username as a parameter

[eluser]AndrewTurner[/eluser]
Is it possible for users to have membership in multiple groups?

[eluser]Ben Edmunds[/eluser]
AndrewTurner,

Not yet but it is in the plans.




Theme © iAndrew 2016 - Forum software by © MyBB