The entire website requires a user to login before viewing the page. If the user is not logged in, he gets redirected to the login/registration page.
Problem: When a user that is not logged in types in a url like http://www.domain.com/listings/1234
, he will be shown that page, but with a darkened page that prevents the user from interacting with the page (jQuery stuff, not a problem here), and a popup modal box with a link to the (Tank Auth) login page http://www.domain.com/login
.
After logging in from the login page, the user will be redirected back to the usual page one gets after logging in, ie: http://www.domain.com
but that page is passed the variable 1234
.
In short: I want the user that has not logged in and has entered the website at http://www.domain.com/listings/1234
to NOT be redirected to http://www.domain.com/login
yet, but instead remain on http://www.domain.com/listings/1234
and be shown a modal box with a link to the login page http://www.domain.com/login
where if he logins in, he will be redirected back to http://www.domain.com/
instead of the usual page he gets after login and be passed the variable 1234
.
How can this be done using Codeigniter?
This is what I have now:
Listings controller
function index(listing_id) {
$this->load->module('auth');
if(!$this->auth->tank_auth->is_logged_in()) {
redirect('login');
}
// Some calls to database etc here...
$this->load->view('listings', $data);
}
There are several ways that your question can be accomplished. Hopefully this solution would give some ideas on how to accomplish this.
The solution below uses jquery ui dialog to display the modal and jquery .ajax to handle the login form submission.
Conditionally put this code at the bottom of you page before the
</body>
tag if the user is not logged in.Your ajax login controller
If you do it this way then you won't have to rely on codeigniter redirects everything will be handled through ajax.
I hope this gives you an idea of how to handle this.