<?php

class login extends CI_Controller{

    function  index(){

        $this->load->view('include/header');
        $this->load->view('login_form');
        $this->load->view('include/footer');

    }

    function  validate_credentials(){

        $this->load->model('membership_model');
        $query=$this->membership_model->validate();


        if($query){
            $data=array(

                'username'=>$this->input->post('username'),
                'is_logged_in'=>ture

            );

            $this->session->set_userdata($data);
            redirect('site/members_area');
        }
    }
}




function signup(){

    $this->load->view('includes/header');
    $this->load->view('signup_form');
    $this->load->view('include/footer');
}


function create_member(){
    $this->load->liblary('form_validation');


    $this->form_validation->set_rules('first_name','Name','trim|required');
    $this->form_validation->set_rules('Last_name','Last Name','trim|required');
    $this->form_validation->set_rules('email','Email Address','trim|required');
    $this->form_validation->set_rules('user_name','User_name','trim|required|minlength[4]');
    $this->form_validation->set_rules('password','Password','trim|required|minlength[4]');
    $this->form_validation->set_rules('first_name','Name','trim|required');

    if($this->form_validation->run()==FALSE){

        $this->load->view('includes/header');
        $this->load->view('signup_form');
        $this->load->view('include/footer');

    }
    else{

        $this->load->model('membership_model');

        if($query= $this->membership_model->create_member()){

            $data['account_created']='yur account has been created .<br/><br/> you mey now login.';

            $this->load->view('includes/header');
            $this->load->view('signup_form',$data);
            $this->load->view('include/footer');
        }

        else{
            $this->load->view('includes/header');
            $this->load->view('signup_form');
            $this->load->view('include/footer');

        }
    }

}


function check_if_username_exists($requested_username){

    $this->load->model('membership_model');

    $username_avalable= $this->membership_model->check_if_username_exists($requested_username);

    if($username_avalable){

        return TRUE;

    }
    else
    {

        return FALSE;
    }
}






?>