Guest User

Untitled

a guest
May 27th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2.  
  3. class User_Model extends ORM {
  4.  
  5. protected $ignored_columns = array('confirm');
  6.  
  7. public function validate(array & $array, $save = FALSE)
  8. {
  9. $array = Validation::factory($array)
  10. ->pre_filter('trim')
  11. ->add_rules('username','required', array($this, '_key_exists'), 'is_string')
  12. ->add_rules('email', 'required', 'valid::email', array($this, '_key_exists'))
  13. ->add_rules('password', 'required', 'alpha_numeric')
  14. ->add_rules('confirm', 'matches[password]')
  15. ->add_rules('hash', 'required', 'length[32]', 'alpha_numeric');
  16.  
  17. return parent::validate($array, $save);
  18. }
  19.  
  20. public function __set($key, $value)
  21. {
  22. if ($key === 'password')
  23. {
  24. $value = md5($value);
  25. }
  26.  
  27. return parent::__set($key, $value);
  28. }
  29.  
  30. public function _key_exists($username)
  31. {
  32. return (bool) ! ORM::factory('user', $username)->loaded;
  33. }
  34.  
  35. public function unique_key($id) {
  36.  
  37. if (empty($id) OR is_numeric($id))
  38. {
  39. return $this->primary_key;
  40. } elseif (valid::email($id)) {
  41. return 'email';
  42. } else {
  43. return 'username';
  44. }
  45. }
  46.  
  47. };
Add Comment
Please, Sign In to add comment