Skip to content

Commit

Permalink
Registration fix
Browse files Browse the repository at this point in the history
  • Loading branch information
katzgrau committed Nov 29, 2011
1 parent 9ecaf26 commit 4302851
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions application/config/form_validation.php
Expand Up @@ -5,13 +5,13 @@
array (
'field' => 'username',
'label' => 'Username',
'rules' => 'required|min_length[4]|max_length[16]|alpha_dash'
'rules' => 'required|min_length[4]|max_length[16]|alpha_dash|callback_username_check'
),

array (
'field' => 'email',
'label' => 'Email',
'rules' => 'required|valid_email'
'rules' => 'required|valid_email|callback_email_check'
),

array (
Expand Down
32 changes: 32 additions & 0 deletions application/controllers/contributors.php
Expand Up @@ -155,6 +155,38 @@ public function edit()
$this->load->view('contributors/edit', $data);
}

/**
* A validation callback for making sure usernames aren't re-used
* @param string $email
* @return bool
*/
public function username_check($username)
{
$this->load->model('contributor');
$this->load->library('form_validation');

if(!Contributor::findByUsername($username)) return true;

$this->form_validation->set_message('username_check', 'This username has already been used');
return FALSE;
}

/**
* A validation callback for making sure email addresses aren't re-used
* @param string $email
* @return bool
*/
public function email_check($email)
{
$this->load->model('contributor');
$this->load->library('form_validation');

if(!Contributor::findByEmail($email)) return true;

$this->form_validation->set_message('email_check', 'This email has already been used');
return FALSE;
}

/**
* A CodeIgniter validation callback for checking to see the the anti-spam
* robot check was correct
Expand Down
12 changes: 12 additions & 0 deletions application/models/contributor.php
Expand Up @@ -52,6 +52,18 @@ public static function findById($user_id)
return $CI->db->get_where('contributors', array('id' => $user_id))->row(0, 'Contributor');
}

/**
* Get a contributor by his email
* @param int $email
* @return Contributor
*/
public static function findByEmail($email)
{
$CI = &get_instance();
return $CI->db->get_where('contributors', array('email' => $email))->row(0, 'Contributor');
}


/**
*
* @param string $username
Expand Down
2 changes: 1 addition & 1 deletion sparks/access/0.0.2/config/access.php
Expand Up @@ -12,7 +12,7 @@
);

# The realm. Should be somethng like Your Site Name
$config['access_realm'] = "Restricted Site";
$config['access_realm'] = "GetSparks.org";

# Only show the prompt for base URLs that conform to this pattern.
# This is a standard perl regular expression.
Expand Down

0 comments on commit 4302851

Please sign in to comment.