Welcome Guest, Not a member yet? Register   Sign In
how should I require login (with rsauth) on a view?
#1

[eluser]Dave Rau[/eluser]
Quick question; what’s the easiest way to require login with rsauth on an entire group of views, or per view, or even to include as a header. What options do I have?

Right now I’m doing this for each controller:
Code:
function home() {
         $loginform = $this->rsauth->login(TRUE);
         if (!$this->rsauth->check()){
             redirect("");
         }
        $this->load->view('manage_photos/home', $data);
    }
#2

[eluser]Dave Rau[/eluser]
I've solved my own problem, but I'm curious: is there a way to do this without a new controller?

I ended up creating a new controller called logincheck.php and here's what that file looked like:
Code:
class Logincheck extends Controller {

    function Logincheck() {
        parent::Controller();
        $this->load->helper('form');
        $this->load->helper('url');
        $this->load->helper('file');

        // rsauth for login
        $this->load->library("rsauth");
        $this->load->model("rsauth_mng_model");

        // gallery
        $this->load->model("m_gallery");
    }

    function login(){
        $this->load->view('login');
    }


}

Then in my main controller (called manage_photos) I set this up:
Code:
class Manage_photos extends Controller {

    function Manage_photos() {
        parent::Controller();
        $this->load->helper('form');
        $this->load->helper('url');
        $this->load->helper('file');
        // rsauth for login
        $this->load->library("rsauth");
        $this->load->model("rsauth_mng_model");

        // gallery
        $this->load->model("m_gallery");
        
        if ($this->rsauth->login(TRUE) != '')
        {
            redirect('logincheck/login');
        }
    }

// login stuff
     function index() {
             redirect("manage_photos/home");
     }

      function logout(){
         $this->rsauth->logout();
         redirect("/gallery.php");
     }


    function home() {

        //$this->load->model("m_gallery");
        //$data['query'] = $this->m_gallery->getrecentphotos();
        $this->db->order_by("id", "desc");
        $this->db->order_by("album");
        $data['query'] = $this->db->get('gallery', 20);
        $data['album_query'] = $this->db->get('gallery_albums');
        $this->load->view('manage_photos/home', $data);
    }

I post this for others in my situation; I'm a designer first, programmer second or third, so OOP concepts are still a little over my head. I found this comment on the PHP.net site very useful for describing what a PHP class is and how it's used.




Theme © iAndrew 2016 - Forum software by © MyBB