php - CodeIgniter login form not working -
on tvs scheme seek create login form. form should result in redirect admin panel, missing , not figure out. have set info in database "users" table. info mysql not show when utilize var_dump();
my code in controller folder
class user extends backend_controller { public function __construct() { parent::__construct(); } public function login() { $this->load->helper('language'); $this->lang->load('form_validation', 'lithuanian'); $dashboard = 'admin/dashboard'; $this->user_m->loggedin() == false || redirect($dashboard); $rules = $this->user_m->rules; $this->form_validation->set_rules($rules); if ($this->form_validation->run() == true) { if ($this->user_m->login() == true) { redirect($dashboard); } else { $this->session->set_flashdata('error', 'email/password wrong'); redirect('admin/user/login', 'refresh'); } } $this->data['subview'] = 'admin/user/login'; $this->load->view('admin/_layout_modal', $this->data); } public function logout() { $this->user_m->logout(); redirect('admin/user/login'); }
}
in core folder my_model.php
class my_model extends ci_model { protected $_table_name = ''; protected $_primary_key = 'id'; protected $_primary_filter = 'intval'; protected $_order_by = ''; public $rules = array(); protected $_timestamps = false; function __construct() { parent::__construct(); } public function get($id = null, $single = false) { if ($id != null) { $filter = $this->_primary_filter; $id = $filter($id); $this->db->where($this->_primary_key, $id); $method = 'row'; } elseif ($single == true) { $method = 'row'; } else { $method = 'result'; } if (!count($this->db->ar_orderby)) { $this->db->order_by($this->_order_by); } homecoming $this->db->get($this->_table_name)->$method(); } public function get_by($where, $single = false) { $this->db->where($where); homecoming $this->get(null, $single); } public function save($data, $id = null) { //timestamps if ($this->_timestamps == true) { $now = date('y-m-d h:i:s'); $id || $data['created'] = $now; $data['modified'] = $now; } //insert if ($id === null) { !isset($data[$this->_primary_key]) || $data[$this->_primary_key] == null; $this->db->set($data); $this->db->insert($this->_table_name); $id = $this->db->insert_id(); } //update else { $filter = $this->_primary_filter; $id = $filter($id); $this->db->set($data); $this->db->where($this->_primary_key, $id); $this->db->update($this->_table_name); } homecoming $id; } public function delete($id) { $filter = $this->_primary_filter; $id = $filter($id); if (!$id) { homecoming false; } $this->db->where($this->_primary_key, $id); $this->db->limit(1); $this->db->delete($this->_table_name); }
}
in model folder user_m.php
<?php class user_m extends my_model { protected $_table_name = 'users'; protected $_order_by = 'name'; public $rules = array( 'email' => array( 'field' => 'email', 'label' => 'email', 'rules' => 'trim|required|valid_email|xss_clean' ), 'password' => array( 'field' => 'password', 'label' => 'password', 'rules' => 'trim|required' ) ); function __construct() { parent::__construct(); } public function login() { $user = $this->get_by(array( 'email' => $this->input->post('email'), 'password' => $this->hash($this->input->post('password')), ), true); if (count($user)) { //log in user $data = array( 'íd' => $user->id, 'email' => $user->email, 'name' => $user->name, 'loggedin' => true, ); $this->session->set_userdata($data); } } public function register() { } public function logout() { $this->session->sess_destroy(); } public function loggedin() { homecoming (bool) $this->session->userdata('loggedin'); } public function hash($string) { homecoming hash('sha512', $string . config_item('encryption_key')); }
}
and in view folder login.php
<?php if (validation_errors() !== '') { echo "<div class='alert alert-warning alert-dismissible' role='alert'> <button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>×</span><span class='sr-only'>close</span></button> <strong>warning!</strong>"; echo validation_errors(); echo "</div>"; } ?> <?php echo form_open(); ?> <div class="form-signin"> <?php $data = array( 'name' => 'email', 'class' => 'form-control', 'placeholder' => 'email' ); echo form_input($data); $data = array( 'name' => 'password', 'class' => 'form-control', 'placeholder' => 'password' ); echo form_password($data); echo form_submit('submit', $login, 'class="btn btn-lg btn-primary"'); echo anchor('admin/user/auth/forgot_password', $forget_password, 'class="pull-right"'); ?> </div> <?php echo form_close(); ?>
php codeigniter
No comments:
Post a Comment