Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login(){
- // Prohibit access if already logged in
- $this->User_model->session_comprobate_member();
- $this->form_validation->set_rules('username','Username','trim|required|min_length[4]');
- $this->form_validation->set_rules('password','Password','trim|required|min_length[4]');
- if ($this->form_validation->run() == FALSE){
- //Load View Into Template
- $this->template->load('public','login','users/login');
- } else {
- // Get Post Data from Database
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $enc_password = md5($password);
- $data_user = $this->User_model->login($username, $enc_password);
- if($data_user == true){
- $user_id = $this->User_model->get_userid($username);
- $users = $this->User_model->get_username($user_id);
- if($users->active == 0){
- // Create error
- $this->session->set_flashdata('error', 'This account is banned or inactive');
- // Redirect to page
- redirect('dashboard/login');
- }
- if($users->is_admin == 0){
- // Create error
- $this->session->set_flashdata('error', 'You do not have permission to view this page');
- // Redirect to page
- redirect('dashboard/login');
- }
- if($users->is_member == 0){
- // Create error
- $this->session->set_flashdata('error', 'This account does not exists. Please try again.');
- // Redirect to page
- redirect('dashboard/login');
- } else {
- $sess_data = array(
- 'user_id' => $user_id,
- 'username' => $username,
- 'occupation' => 'occupation',
- 'is_member' => true,
- 'is_admin' => true,
- 'active' => true
- );
- // Set Session Data
- $this->session->set_userdata($sess_data);
- // Create Message
- $this->session->set_flashdata('success', 'You are logged in');
- // Redirect to pages
- redirect('dashboard');
- }
- } else {
- // Create Error
- $this->session->set_flashdata('error', 'Invalid Login');
- // Redirect to pages
- redirect('dashboard/login');
- }
- }
- }
- $this->session->set_flashdata('error', 'This account is banned or inactive');
- public function get($id)
- {
- $this->db->where('id', $id);
- $query = $this->db->get($this->table);
- return $query->row();
- }
- public function login($username, $password)
- {
- $this->db->select('*');
- $this->db->from($this->table);
- $this->db->where('username', $username);
- $this->db->where('password', $password);
- $this->db->limit(1);
- $query = $this->db->get();
- if ($query->num_rows() == 1) {
- return $query->row()->id;
- } else {
- return false;
- }
- }
- //I need to work on these two
- public function get_username($users) {
- $this->db->select('id');
- $this->db->from($this->table);
- $this->db->where('username', $users);
- return $this->db->get()->row;
- }
- public function get_userid($user_id) {
- $this->db->select('id');
- $this->db->from($this->table);
- $this->db->where('id', $user_id);
- return $this->db->get()->row();
- }
- ///
- //Check if admin
- public function is_admin($id) {
- $this->db->select('is_admin');
- $this->db->from($this->table);
- $this->db->where('id', $id);
- $is_admin = $this->db->get()->row('is_admin');
- if ($is_admin == 0) {
- redirect('/');
- } else {
- redirect('admin');
- }
- }
- //Check if member
- public function is_member($id) {
- $this->db->select('is_member');
- $this->db->from($this->table);
- $this->db->where('id', $id);
- $is_member = $this->db->get()->row('is_member');
- if ($is_member == 0) {
- redirect('/');
- } else {
- redirect('dashboard/login');
- }
- }
- //Check if active
- public function is_active($id) {
- $this->db->select('active');
- $this->db->from($this->table);
- $this->db->where('id', $id);
- $is_active = $this->db->get()->row('active');
- if ($is_active == 0) {
- redirect('/');
- } else {
- redirect('dashboard/login');
- }
- }
Add Comment
Please, Sign In to add comment