Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class UserModel extends ModelDbDecorator
- {
- protected $table = 'users';
- /**
- * Find user by email and password
- *
- * @param string $email
- * @param string $password
- * @return array
- */
- public function findUser($email, $password)
- {
- $this->db->where("email", $email);
- $this->db->where("password", $this->hashPassword($password));
- $query = $this->db->get($this->table);
- if ($query->num_rows() == 1) {
- return $query->row();
- }
- return null;
- }
- /**
- * Update ip and time for a last login
- *
- * @param string $id
- * @param string $ip
- */
- public function logLastLogin($id, $ip)
- {
- $this->db->where("id", $id);
- $this->db->update($this->table, array("last_ip" => $ip, "last_login" => time()));
- }
- //@TODO
- public function add_notify($email, $firstname, $service = '')
- {
- $this->db->query("INSERT INTO BETA_REGISTRATION VALUES('" .$email. "','". $firstname ."','". $service ."')");
- }
- /**
- * get all users filtered
- *
- * @access public
- * @param $type
- */
- public function getUsersByType($type='')
- {
- $sql = "SELECT *, (reported_false_count + comments_spam_count) as crime_count FROM users";
- if(strlen($type)>0)
- {
- $sql = $sql . " WHERE user_type = '" . $type . "'";
- }
- log_message('debug',$sql);
- $result = $this->db->query($sql)->result();
- if(count($result)>0)
- {
- $rows = array();
- foreach($result as $row)
- {
- $rows[] = $row;
- }
- return $rows;
- }
- return false;
- }
- /**
- * Overidden for password hashing
- */
- public function set($key, $value = '', $escape = TRUE)
- {
- if ('password' == $key) {
- $value = $this->hashPassword($value);
- }
- parent::set($key, $value, $escape);
- }
- /**
- * Overidden for password hashing
- */
- public function save($fields = array())
- {
- if (isset($fields['password'])) {
- $fields['password'] = $this->hashPassword($fields['password']);
- }
- return parent::save($fields);
- }
- /**
- * Hash a password
- *
- * @access private
- * @param string $password
- * @author shawn.lee@picturersurf.org
- * @return string
- */
- private function hashPassword($password)
- {
- return sha1($password);
- }
- }
Add Comment
Please, Sign In to add comment