Welcome Guest, Not a member yet? Register   Sign In
help needed: integrate tank_auth into my website
#1

[eluser]lolmann[/eluser]
hello,

i've tested and liked the (tank) <a href="http://codeigniter.com/wiki/The_Auth_Library/">auth library</a>.

i am fairly new to ci but have read the user guide and understood the principles of mvc programming.

still, i struggle with some basic issues and one of them is integrating the auth library into my website.

the library comes with a controller. when i call it like this http://localhos/auth it works just fine. it displays a login form, logs me in, end so on.

but how do i use the power of the library without calling the controller /auth?

say, i have a website that displays a little login form at the top of each page. creating the form in html is no problem but auth actually needs some data (for example, the variable $login_by_username) in order to determine whether a user can login by username or only by email. how do i get this data?

i get that i have to somehow load the tank_auth library in my main controller which I did ($this->load->library('tank_auth')Wink but it doesn't solve the problem.

can anybody help?
#2

[eluser]Victor Michnowicz[/eluser]
I have had good luck with Ion Auth. It has some really good documentation too.
#3

[eluser]lolmann[/eluser]
thank you elvicmic, i'll have a look at that.

but if it's possible i would like to stick with tank_auth because it seems to be very powerful.

to be clear: the problem here is not one of tank_auth (I think) but rather my understanding of how to use libraries correctly in an existing website.
#4

[eluser]Victor Michnowicz[/eluser]
Glancing at the Tank Auth source, I am guessing it would prolly go something like this (untested):

In your controller:

Code:
function __construct()
{
$this->load->library('tank_auth');
}

function login()
{
$username = $_POST['username'];
$password = $_POST['password'];

if ($this->tank_auth->login($username, $password, TRUE, TRUE, FALSE))
{
// the user is logged in!
redirect('members_only');
}

else
{
// the user did not supply the correct username and/or password
}

}

And then in your user-only area you would have something like this in your controller:

Code:
function __construct()
{
$this->load->library('tank_auth');
if (!$this->tank_auth->is_logged_in())
{
redirect('login');
}
}
#5

[eluser]Nick_MyShuitings[/eluser]
Use the included example controller as a guide. For example, that controller will load the pertinent library/models/helpers etc and shows you a simple way of integrating.

You can check and see the form generated by the /login example, and will see to which method that form will be submitted. Check that method in the controller and you will be able to learn how the library processed the logon.

Most of the well packaged libraries are packaged like this with example controllers and views so that you don't have to snoop through the source code... although, as elvicmic shows, the source is pretty clean.




Theme © iAndrew 2016 - Forum software by © MyBB