Welcome Guest, Not a member yet? Register   Sign In
what is the best way to use login module ?
#1

[eluser]Pokhara[/eluser]
I made a login controller it's difficult to include it in other controller in the admin section. what is the best way to include auth controller ? Also is there any very simple auth module out there which i can use in my custom cms ? I just need a secure way to login and update the pages. Thanks

Regards
#3

[eluser]überfuzz[/eluser]
The boring but healthy answer is your own log in is the best for your site.

Personally I use a login controller and a auth library working in CI. This however is a result of the form_validation helper. It's not possible to run a form validation external. Well I like this particular helper to must to skip it.

1.a The controller login.php runs the form_validation.
1.b The custom rule callback__process_login can be used.
1.c This function uses a log_model to search the database for user.

2. The auth library is used to restrict areas, redirect when 403, log out, etc. (Reachable from every controller.)
#4

[eluser]Pokhara[/eluser]
hi überfuzz

do you have a sample of that controller ?
#5

[eluser]nelson.wells[/eluser]
I just wrote a brief tutorial about how you could write your own authentication library. It might help get you started.

http://www.nelsonwells.net/blog/2010/05/...n-library/
#6

[eluser]überfuzz[/eluser]
[quote author="nelson.wells" date="1273565289"]I just wrote a brief tutorial about how you could write your own authentication library. It might help get you started.

http://www.nelsonwells.net/blog/2010/05/...n-library/[/quote]

I had a brief glance at your tutorial. There are things I'd do that you haven't done and there are things I'd do different. Wish goes to prove my point higher up in this thread...

Thoughts on your authex library...
1. I prefer to have my models handling database querys. Your style tends to bloat the controllers.
2. Use of a redirect function. Redirect users to 403 if credentials are bad.
3. And of course, use the lovely form_validation helper if I'm tinkering with CI. :-)

Nice going though!!!
#7

[eluser]Buso[/eluser]
This is how I do it:

I have a 'users' controller, an 'auth' library, and a base controller (all of my controllers extends this controller. You can set MY_Controller in /libraries. I do it another way but this is simpler). If I need to restrict access to all my site, inside base controller i put something like
Code:
$this->auth->check('some_resource')

That will check if the user has access to the mentioned resource, eg: 'enter_site'

Inside Users controller I have my login method, which runs the needed validations, and if everything is fine then goes this:
Code:
$this->auth->login()

My auth library will assume 'login' data is at $this->input->post('login'), same for password. That's if you need 'automagic'. Optionally you can set the arguments yoursef ->login($user,$password)

Auth will do everything else but the queries, which are handled by auth_model.

I hope this is helpful.
#8

[eluser]überfuzz[/eluser]
[quote author="Buso" date="1273580591"]...
Inside Users controller I have my login method, which runs the needed validations...[/quote]

Code:
//The main idea of my login controller, use or make your own functions to run it smoothly on your system...
    function log_in()
    {
        if ($this->_validate_form_fields() === FALSE)
        {
            $this->index();
        }
        else
        {
            redirect('/*link to wonderland*/');
        }
    }

    function _process_login()
    {
        //use your profile model and check credentials.
        
    }

    //extend CI_Form_Validation with _process_login
    function _validate_form_fields()
    {
        //Setup default rules.
        //Use your custom rule.
        $this->form_validation->set_message('_process_login',"You're kidding right!?");
        //if process_login === FALSE -> error message is thrown.
        return $this->form_validation->run();
    }

Like I said, this login controller is used because of how the form_validation works. If I could run it outside the controller handling the login I'd do that.
#9

[eluser]Pokhara[/eluser]
hi nelson do u have eample of login n register page ? i have done so with contrller but not done with library. I like the script, i was actually looking script like that.




Theme © iAndrew 2016 - Forum software by © MyBB