Skip to content

Commit

Permalink
Fixed #3111
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert De Deckere committed Jul 24, 2010
1 parent c2c62e2 commit eb30119
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions classes/model/auth/user.php
Expand Up @@ -162,7 +162,7 @@ public function complete_login()
*/
public function username_available(Validate $array, $field)
{
if ($this->unique_key_exists($array[$field]))
if ($this->unique_key_exists($array[$field], 'username'))
{
$array->error($field, 'username_available', array($array[$field]));
}
Expand All @@ -178,7 +178,7 @@ public function username_available(Validate $array, $field)
*/
public function email_available(Validate $array, $field)
{
if ($this->unique_key_exists($array[$field]))
if ($this->unique_key_exists($array[$field], 'email'))
{
$array->error($field, 'email_available', array($array[$field]));
}
Expand All @@ -188,13 +188,20 @@ public function email_available(Validate $array, $field)
* Tests if a unique key value exists in the database.
*
* @param mixed the value to test
* @param string field name
* @return boolean
*/
public function unique_key_exists($value)
public function unique_key_exists($value, $field = NULL)
{
if ($field === NULL)
{
// Automatically determine field by looking at the value
$field = $this->unique_key($value);
}

return (bool) DB::select(array('COUNT("*")', 'total_count'))
->from($this->_table_name)
->where($this->unique_key($value), '=', $value)
->where($field, '=', $value)
->where($this->_primary_key, '!=', $this->pk())
->execute($this->_db)
->get('total_count');
Expand Down

0 comments on commit eb30119

Please sign in to comment.