Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('SYSPATH') OR die('No direct access allowed.');
- class User_Model extends ORM {
- protected $ignored_columns = array('confirm');
- public function validate(array & $array, $save = FALSE)
- {
- $array = Validation::factory($array)
- ->pre_filter('trim')
- ->add_rules('username','required', array($this, '_key_exists'), 'is_string')
- ->add_rules('email', 'required', 'valid::email', array($this, '_key_exists'))
- ->add_rules('password', 'required', 'alpha_numeric')
- ->add_rules('confirm', 'matches[password]')
- ->add_rules('hash', 'required', 'length[32]', 'alpha_numeric');
- return parent::validate($array, $save);
- }
- public function __set($key, $value)
- {
- if ($key === 'password')
- {
- $value = md5($value);
- }
- return parent::__set($key, $value);
- }
- public function _key_exists($username)
- {
- return (bool) ! ORM::factory('user', $username)->loaded;
- }
- public function unique_key($id) {
- if (empty($id) OR is_numeric($id))
- {
- return $this->primary_key;
- } elseif (valid::email($id)) {
- return 'email';
- } else {
- return 'username';
- }
- }
- };
Add Comment
Please, Sign In to add comment