[eluser]Robert M.[/eluser]
Hi @ all,
i use the authlib from the wiki
http://codeigniter.com/wiki/auth/ and want to do some routings but get some problems with that.
I want to call my controller via
http://mysite.com/index.php/test_control...dex/123456
in the test_controller i want to check with the authlib if a user is logged in or not? When not they get redirected to login page... otherway they get logged in to another controller...
test_controller
Code:
function index(){
$my_third_uri_segment=$this->uri->segment(3);
//if im not logged in
if(!$this->authlib->isValidUser()){
redirect('auth/login/'.$my_third_uri_segment.'/','location');
//if im allready logged in as Member
if($this->authlib->getSecurityRole()=='Member'){
redirect('other_controller/index/'.$my_third_uri_segment.'/','location');
}
when im allready logged in as an Member i get redirected to the other_controller with the right uri segment...
http://mysite.com/index.php/other_contro...dex/123456
but when im not logged in i get..
http://mysite.com/index.php/auth/login/123456
so here is everything ok but when i want to login i get redirected to the other_controller but without
Code:
$my_third_uri_segment
i have in the auth.php from the authlib this function...
Code:
function login()
{
$rules[$this->config->item('auth_user_name_field')] = $this->config->item('auth_user_name_field_validation_login');
$rules[$this->config->item('auth_user_password_field')] = $this->config->item('auth_user_password_field_validation_login');
//additionalLoginRules($rules);
$this->validation->set_rules($rules);
if ($this->validation->run() && $this->authlib->login())
redirect($this->config->item('auth_login_success_action'), 'location'); //On success redirect user to default page
else
{
$this->db_session->sess_gc();
$this->index();
}
}
and in the Authlib.php
Code:
function login()
{
if (!$this->obj->config->item('auth'))
return;
$message = $this->obj->lang->line('auth_invalid_user_message');
if ($this->obj->db_session)
{
$values = $this->getLoginForm();
$username = (isset($values[$this->obj->config->item('auth_user_name_field')]) ? $values[$this->obj->config->item('auth_user_name_field')] : false);
$password = (isset($values[$this->obj->config->item('auth_user_password_field')]) ? $values[$this->obj->config->item('auth_user_password_field')] : false);
$autoLogin = (isset($values[$this->obj->config->item('auth_user_autologin_field')]) ? $values[$this->obj->config->item('auth_user_autologin_field')] : 0);
if (($username != false) && ($password != false))
{
$password = $this->obj->encrypt->hash($password, 'md5');
//Use the input username and password and check against 'users' table
$query = $this->obj->usermodel->getUserForLogin($username, $password);
if ($query->num_rows() > 0)
{
$row = $query->row();
$user_id = $row->{$this->obj->config->item('auth_user_id_field')};
$username = $row->{$this->obj->config->item('auth_user_name_field')};
$activated = $row->{$this->obj->config->item('auth_user_activated_field')};
if ($activated == 1)
{
$this->_set_logindata($user_id, $username);
$this->_set_security($user_id);
if ($autoLogin)
$this->_set_login_cookie($user_id);
$this->obj->db_session->set_flashdata(AUTH_STATUS, $this->obj->lang->line('auth_login_message'), 2);
return true;
}
else
$message = $this->obj->lang->line('auth_not_activated_user_message');
}
}
}
//On error send user back to login page, and add error message
$this->obj->db_session->set_flashdata(AUTH_STATUS, $message, 1);
return false;
}
i think i must change something in this line in auth.php
Code:
redirect($this->config->item('auth_login_success_action'), 'location'); //On success redirect user to default page
the auth_login_success_action is fixed in the authconfig.php but i want to redirect to the controller with the $my_third_uri_segment so i tried these...
Code:
redirect('other_controller/index/'.$my_third_uri_segment.'/', 'location');
now im get redirected but the $my_third_uri_segment is missed and i dont know how this is happend...
can someone help me with that???
regards Robert