Welcome Guest, Not a member yet? Register   Sign In
User Authentication - Placement of code?
#1

[eluser]RyanH[/eluser]
I realize there are libraries out there (such as ErkanaAuth) that do this for you. However for the purposes of learning I'm trying to create some user authentication of my own. I'm not doing this in the form of a library but rather just placing the code into the controllers/view files. That being said, this brings me to my question. How do you setup your files and the placement of your code?

For example, I have a login page (login controller) that requires only an email and a password. The login controller, within the index function, validates the fields and then checks the database to see if the email and passwords match and if they do, redirects them to a login_complete view file. If it fails, it reloads the login page.

I've also added sessions into the mix and so far they seem to be working fine. However, what I'd like to know is what code to use, and where to place it (view files or controllers), that checks to see if the user is logged in, and if not, displays the login page. Essentially right now my login_complete page looks basically like this:
Code:
<? if(!$this->session->userdata('session_id'))
        {
            redirect('login', 'location');
         } else {
                echo 'Welcome ' . $this->session->userdata('session_id') . ' (Logout)';
        }
                // HTML/page information goes here
        ?>
Am I setting this up the wrong way? If so, what would be a better way? How would I set it up to use a logout function? Do I put a function in the login controller file?

Thanks. Smile


Messages In This Thread
User Authentication - Placement of code? - by El Forum - 01-21-2008, 12:31 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 12:40 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 12:48 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 12:59 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 01:10 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 02:55 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 03:55 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 04:01 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 04:22 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 06:05 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 06:21 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 06:37 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 07:07 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 07:11 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 07:25 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 07:34 PM
User Authentication - Placement of code? - by El Forum - 01-21-2008, 08:01 PM
User Authentication - Placement of code? - by El Forum - 01-23-2008, 03:43 PM
User Authentication - Placement of code? - by El Forum - 01-23-2008, 05:42 PM
User Authentication - Placement of code? - by El Forum - 01-25-2008, 03:55 AM
User Authentication - Placement of code? - by El Forum - 01-25-2008, 08:58 AM
User Authentication - Placement of code? - by El Forum - 01-25-2008, 09:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB