Welcome Guest, Not a member yet? Register   Sign In
Code Organization
#6

[eluser]jedd[/eluser]
[quote author="m40" date="1250053222"]But isn't it redundant to have the same functoinality once in the Model and again in MY_Controller? I know the function in your MY_Controller is smaller and not the same, but still I assume a part of it is the same.[/quote]

No - my model hashes the password on the way in, does a DB lookup to check if the account is locked, another to see if the originating IP address is being spurned, then does another query with the user/pass and deals with not finding a username that matches, or a failed password hit, updates log files (perhaps) or attempted logins (perhaps), returns different values depending on the nature of the error (wrong user, wrong password, too many tries attempted) and so on.

My controller function does something different - and much simpler - it verifies that I'm allowed to look at a given controller (or method) and if I'm not it redirects me to somewhere special. It means I can have (usually in each of my controller's constructors) a line like this:
Code:
$this->_ensure_authenticated_user( "Forum" );

In MY_Controller, this is what's being called:
Code:
function  _ensure_authenticated_user ( $page_message = "this")  {
    if (! $this->session->userdata('login_name'))  {
        $this->session->set_flashdata('user_needs_to_login', $page_message);
        $this->session->set_flashdata('return_to_page', uri_string());
        redirect('/people/login');
        }
    }

Alternatively I've used a helper function before, to get a simple true/false on whether the user is logged in
Code:
function pdb_is_logged_in()  {
    $CI =& get_instance();
    return ($CI->session->userdata('id')) ? $CI->session->userdata('id') : FALSE ;
    } // end-function pdb_is_logged_in ()


Messages In This Thread
Code Organization - by El Forum - 08-11-2009, 11:51 AM
Code Organization - by El Forum - 08-11-2009, 12:01 PM
Code Organization - by El Forum - 08-11-2009, 05:38 PM
Code Organization - by El Forum - 08-11-2009, 05:47 PM
Code Organization - by El Forum - 08-11-2009, 06:00 PM
Code Organization - by El Forum - 08-11-2009, 06:41 PM
Code Organization - by El Forum - 08-12-2009, 02:33 AM
Code Organization - by El Forum - 08-12-2009, 05:00 AM
Code Organization - by El Forum - 08-12-2009, 05:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB