Welcome Guest, Not a member yet? Register   Sign In
Question about tank_auth
#1

[eluser]oualid[/eluser]
Hi.

I downloaded the library tank_auth and I am testing it.

I have a question about the login function:

I created a new file welcome2.php under controller:
/controller/welcome2.php

Code:
class Welcome2 extends Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->helper('url');
        $this->load->library('tank_auth');
    }

    function index()
    {
        if (!$this->tank_auth->is_logged_in()) {
            redirect('/auth/login/');
        } else {
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $this->load->view('welcome2', $data);
        }
    }
}

The file welcome.php is exactly the same.

In config.php I changed: $config['sess_use_database'] value to TRUE.

and

routes.php: $route['default_controller'] = "welcome";


When I login to welcome2.php I will be redirected to welcome.php because of the setting in routes.php.
What should I do to redirect to welcome2.php instead to welcome.php?

Best regards.

/Oualid
#2

[eluser]umefarooq[/eluser]
you have to change redirect function parameter where login is successful

Code:
redirect('welcome2');

it will be redirected to welcome2 controller.
#3

[eluser]oualid[/eluser]
OK!

But how to do if I use other files like welcome3, welcome4, welcome5 and so on?
#4

[eluser]umefarooq[/eluser]
one question is your redirection will be fix or base on type of users, if it is base on user type you have to check user type and redirect according to that.
#5

[eluser]oualid[/eluser]
I did the following:

In /controller/welcome2.php I added the following lines:


Code:
class Welcome2 extends Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->helper('url');
        $this->load->library('tank_auth');
        $this->load->library('session');   //New line added    
  }


        function index()
        {
            if (!$this->tank_auth->is_logged_in()) {

                $this->session->set_userdata('redirect_url', $this->uri->uri_string()); //New line added  

                redirect('/auth/login/');

                $this->session->unset_userdata('redirect_url'); //New line added  

            } else {
                $data['user_id']    = $this->tank_auth->get_user_id();
                $data['username']    = $this->tank_auth->get_username();
                $this->load->view('welcome2', $data);
            }
        }
    }


And in /controller/auth.php I added the following lines in function login():

Code:
if ($this->form_validation->run()) {                                // validation ok
                if ($this->tank_auth->login(
                        $this->form_validation->set_value('login'),
                        $this->form_validation->set_value('password'),
                        $this->form_validation->set_value('remember'),
                        $data['login_by_username'],
                        $data['login_by_email'])) {                                // success
                        $redirect_url = $this->session->userdata('redirect_url');  //New line added
                        redirect($redirect_url); //New line added
                        //redirect('');
                       ...




Theme © iAndrew 2016 - Forum software by © MyBB