Welcome Guest, Not a member yet? Register   Sign In
[help]School Project Here
#22

[eluser]miwrath[/eluser]
im sorry dude...here it is...

my model

Code:
<?php
class User_model extends Model {
    
    function User_model()
    {
        parent::Model();
    }
    
    function check_login($username, $password)
    {
        $shal_password = sha1($password);
              
        $query_str = "SELECT * FROM users WHERE username = ? and password = ?";
        
        $result = $this->db->query($query_str, array($username, $shal_password));
        
      
        
        if ($result->num_rows() == 1)
        {
            return $result->row(0)->teach_id;
        }
        else
        {
            return false;
        }
      
        
    }
    
    
    
}


?>

CONTROLLER

Code:
<?php
class Registrar extends Controller {

    function Registrar()
    {
        parent::Controller();    
    }
    
    function index()
    {
            $this->login();
                    
    }
        
        function secondary_page()
        {
            
        }
        
        
        function main_page()
        {
            if ($this->session->userdata('logged_in'))
            {
                echo 'you are now logged in' ;
                
            }          
            
            else
            {
                redirect('index.php/user/login');
            }
            
          
            
            
        }
        
        function login()
        {
            $this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[50]|xss_clean');  
            $this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[50]|xss_clean');  
                                
                    
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('view_registrar');
            }
            else
            {
                echo 'You are great!';
                //process the input and login the user;
                
                /*$sername = $_POST('username');
                $username = $this->input->post('username');
                $password = $_POST('password');
                $password = $this->input->post('password');
                */
               extract($_POST);
            
               $teach_id = $this->User_model->check_login($username, $password);
              
               if (! $teach_id)
               {
                   //login failed error
                  
                   $this->session->set_flashdata('login_error', TRUE);
                  
                   redirect('index.php');
               }
               else
               {
                   //login

                   $this->session->set_userdata(array(
                                           'logged_in' => TRUE,
                                           'teach_id' => $teach_id
                                                     ));
                  
                   redirect('main_page');
                  
               }
                
            }
            
            // echo $this->db->last_query();
            //exit();  
                  
        }
        
}

?>

VIEWS


Code:
<html>
<head>
<title>Welcome</title>

<style type="text/css">

body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 16px;
font-weight: bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}

code {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}

ul {
list-style: none;
}

ul list{
    margin-top:0;
}

div#login_form{
    width:350px;
    margin: 0px auto;
    border:1px solid #acacac;
    padding:10px;
}


</style>
</head>
<body>

<div id="login_form">
    <h1>Please login.</h1>
    <p>Use the form to login...</p>
    
&lt;?php echo form_open(base_url() . 'index.php/registrar/login'); ?&gt;  
    
    <ul>
    <li>
        <label>Username</label>
        <div>
            &lt;?php echo form_input(array ('id'=> 'username', 'name'=> 'username'));?&gt;        
        </div>
    </li>
    <li>
                <label>Password</label>
        <div>
            &lt;?php echo form_password(array ('id'=> 'password', 'name'=> 'password'));?&gt;        
        </div>    
    </li>
        
    <li>
        &lt;?php
            if ($this->session->flashdata('login_error'))
            {
                echo 'You entered incorrect username or password';
            }
            
            echo validation_errors(); ?&gt;</li>
    
        &lt;?php echo form_submit(array('name' => 'submit'), 'Login'); ?&gt;
        
    </ul>

&lt;?php echo form_close(); ?&gt;
    
</div>


&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
[help]School Project Here - by El Forum - 08-18-2011, 06:56 AM
[help]School Project Here - by El Forum - 08-18-2011, 06:57 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:09 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:10 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:20 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:22 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:31 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:35 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:48 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:55 AM
[help]School Project Here - by El Forum - 08-18-2011, 07:56 AM
[help]School Project Here - by El Forum - 08-19-2011, 05:52 AM
[help]School Project Here - by El Forum - 08-19-2011, 05:59 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:04 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:13 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:23 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:27 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:34 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:36 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:43 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:48 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:52 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:55 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:58 AM
[help]School Project Here - by El Forum - 08-19-2011, 06:58 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:08 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:13 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:18 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:26 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:35 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:38 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:40 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:42 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:45 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:56 AM
[help]School Project Here - by El Forum - 08-19-2011, 07:59 AM
[help]School Project Here - by El Forum - 08-19-2011, 08:04 AM
[help]School Project Here - by El Forum - 08-19-2011, 08:14 AM
[help]School Project Here - by El Forum - 08-19-2011, 08:20 AM
[help]School Project Here - by El Forum - 08-19-2011, 08:33 AM
[help]School Project Here - by El Forum - 08-19-2011, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB