Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created November 7, 2010 06:03
Show Gist options
  • Save iammerrick/665979 to your computer and use it in GitHub Desktop.
Save iammerrick/665979 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
class Model_User extends Model_Auth_User {
protected $_has_many = array(
'user_tokens' => array('model' => 'user_token'),
'roles' => array('model' => 'role', 'through' => 'roles_users'),
);
protected $_rules = array(
'username' => array(
'not_empty' => NULL,
'min_length' => array(4),
'max_length' => array(32),
'regex' => array('/^[-\pL\pN_.]++$/uD'),
'alpha_dash' => array()
),
'password' => array(
'not_empty' => NULL,
'min_length' => array(5),
'max_length' => array(42),
),
'password_confirm' => array(
'matches' => array('password'),
),
'email' => array(
'not_empty' => NULL,
'min_length' => array(4),
'max_length' => array(127),
'email' => NULL,
),
'first_name' => array(
'not_empty' => NULL,
'max_length' => array(255)
),
'last_name' => array(
'not_empty' => NULL,
'max_length' => array(255)
),
'mobile' => array(
'not_empty' => NULL,
'phone' => array(10)
)
);
protected $_filters = array(
'mobile' => array('Model_User::remove_dashes' => array()),
);
protected $_callbacks = array(
'username' => array('username_available'),
'email' => array('email_available'),
);
protected $_labels = array(
'username' => 'username',
'email' => 'email address',
'password' => 'password',
'password_confirm' => 'password confirmation',
'first_name' => 'first name',
'last_name' => 'last name',
'mobile' => 'mobile phone number',
);
protected $_ignored_columns = array('password_confirm');
public static function remove_dashes($value)
{
$value = preg_replace('/\D+/', '', $value);
return $value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment