3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Users_model extends CI_Model { protected $table_name = 'users'; // Добавляет пользователя в базу данных protected function signup_user($data = FALSE) { if (!is_array($data) || !$data) return FALSE; $this->db->insert($this->table_name, $data); return $this->db->insert_id(); } protected function delete($id = FALSE) { if (!$id) return FALSE; $this->db->delete($this->table_name, array('id' => $id)); return $this->db->affected_rows() ? TRUE : FALSE; } public function get_user_info($fields = '*', $user_id = FALSE, $where = FALSE) { if (!$user_id) return FALSE; if (!is_array($where)) $where = array('id' => (int)$user_id); $query = $this->db->select($fields)->get_where($this->table_name, $where); if ($query->num_rows()) { return $query->row(); } return FALSE; } protected function get_users($fields = '*', $where = FALSE, $from = FALSE, $limit = FALSE) { $this->db->select($fields); if (is_array($where)) $this->db->where($where); if ($from !== FALSE and $limit !== FALSE) $this->db->limit($from, $limit); $query = $this->db->get($this->table_name); if ($query->num_rows()) { return $query->result(); } return FALSE; } protected function get_current_user($fields = '*') { $user_id = $this->session->userdata('id'); $query = $this->db->select($fields)->get_where($this->table_name, array('id' => $user_id)); if ($query->num_rows()) { return $query->row(); } return FALSE; } protected function get_user_by_email($fields = '*', $email = FALSE) { if (!$email) return FALSE; $query = $this->db->select($fields)->get_where($this->table_name, array('login' => $email)); if ($query->num_rows()) { return $query->row(); } return FALSE; } protected function update_user_info($user_id = FALSE, $data = FALSE) { if (!$user_id or !$data) return FALSE; if (!$this->is_user_exist($user_id)) return FALSE; $this->db->where('id', $user_id)->update($this->table_name, $data); return $this->db->affected_rows() ? TRUE : FALSE; } protected function is_user_exist($user_id = FALSE) { if (!$user_id) return FALSE; $query = $this->db->select('id')->get_where($this->table_name, array('id' => $user_id)); return $query->num_rows() ? TRUE : FALSE; } public function is_email_exist($email = FALSE) { if (!$email) return FALSE; $query = $this->db->select('id')->get_where($this->table_name, array('login' => $email)); return $query->num_rows() ? TRUE : FALSE; } public function is_logged_in() { return (bool)$this->session->userdata('id'); } public function get_user_group() { return (int)$this->session->userdata('group'); } // Генерит случайные пароли protected function password_verify($password = '', $hash = '') { $this->load->helper('password'); return password_verify($password, $hash); } // Хеширует пароль пользователя protected function password_hash($password = FALSE) { $this->load->helper('password'); $this->load->helper('string'); $hash = password_hash($password, PASSWORD_DEFAULT, array("cost" => 10, "salt" => random_string('alnum', 25))); return $hash; } }
Output for 5.3.0 - 7.1.0
No direct script access allowed