Guest User

Untitled

a guest
May 25th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. <?php
  2.  
  3. class UserModel extends ModelDbDecorator
  4. {
  5.  
  6. protected $table = 'users';
  7.  
  8.  
  9. /**
  10. * Find user by email and password
  11. *
  12. * @param string $email
  13. * @param string $password
  14. * @return array
  15. */
  16. public function findUser($email, $password)
  17. {
  18. $this->db->where("email", $email);
  19. $this->db->where("password", $this->hashPassword($password));
  20. $query = $this->db->get($this->table);
  21. if ($query->num_rows() == 1) {
  22. return $query->row();
  23. }
  24. return null;
  25. }
  26.  
  27. /**
  28. * Update ip and time for a last login
  29. *
  30. * @param string $id
  31. * @param string $ip
  32. */
  33. public function logLastLogin($id, $ip)
  34. {
  35. $this->db->where("id", $id);
  36. $this->db->update($this->table, array("last_ip" => $ip, "last_login" => time()));
  37. }
  38.  
  39. //@TODO
  40. public function add_notify($email, $firstname, $service = '')
  41. {
  42. $this->db->query("INSERT INTO BETA_REGISTRATION VALUES('" .$email. "','". $firstname ."','". $service ."')");
  43. }
  44.  
  45. /**
  46. * get all users filtered
  47. *
  48. * @access public
  49. * @param $type
  50. */
  51. public function getUsersByType($type='')
  52. {
  53. $sql = "SELECT *, (reported_false_count + comments_spam_count) as crime_count FROM users";
  54.  
  55. if(strlen($type)>0)
  56. {
  57. $sql = $sql . " WHERE user_type = '" . $type . "'";
  58. }
  59.  
  60. log_message('debug',$sql);
  61. $result = $this->db->query($sql)->result();
  62.  
  63. if(count($result)>0)
  64. {
  65. $rows = array();
  66. foreach($result as $row)
  67. {
  68. $rows[] = $row;
  69. }
  70. return $rows;
  71. }
  72.  
  73. return false;
  74. }
  75.  
  76. /**
  77. * Overidden for password hashing
  78. */
  79. public function set($key, $value = '', $escape = TRUE)
  80. {
  81. if ('password' == $key) {
  82. $value = $this->hashPassword($value);
  83. }
  84. parent::set($key, $value, $escape);
  85. }
  86.  
  87. /**
  88. * Overidden for password hashing
  89. */
  90. public function save($fields = array())
  91. {
  92. if (isset($fields['password'])) {
  93. $fields['password'] = $this->hashPassword($fields['password']);
  94. }
  95. return parent::save($fields);
  96. }
  97.  
  98. /**
  99. * Hash a password
  100. *
  101. * @access private
  102. * @param string $password
  103. * @author shawn.lee@picturersurf.org
  104. * @return string
  105. */
  106. private function hashPassword($password)
  107. {
  108. return sha1($password);
  109. }
  110.  
  111. }
Add Comment
Please, Sign In to add comment