add validation to UsersController and let users change their own data and add breadcrumbs to user pages

This commit is contained in:
coderkun 2014-05-01 03:22:02 +02:00
commit aed297c33e
8 changed files with 312 additions and 58 deletions

View file

@ -149,24 +149,22 @@
* Check if an username already exists.
*
* @param string $username Username to check
* @param int $userId Do not check this ID (for editing)
* @return boolean Whether username exists or not
*/
public function usernameExists($username)
public function usernameExists($username, $userId=null)
{
$data = $this->db->query(
'SELECT count(id) AS c '.
'SELECT id '.
'FROM users '.
'WHERE username = ? OR url = ?',
'ss',
$username,
\nre\core\Linker::createLinkParam($username)
);
if(!empty($data)) {
return ($data[0]['c'] > 0);
}
return false;
return (!empty($data) && (is_null($userId) || $userId != $data[0]['id']));
}
@ -174,23 +172,21 @@
* Check if an email address already exists.
*
* @param string $email Email address to check
* @param int $userId Do not check this ID (for editing)
* @return boolean Whether email address exists or not
*/
public function emailExists($email)
public function emailExists($email, $userId=null)
{
$data = $this->db->query(
'SELECT count(id) AS c '.
'SELECT id '.
'FROM users '.
'WHERE email = ?',
's',
$email
);
if(!empty($data)) {
return ($data[0]['c'] > 0);
}
return false;
return (!empty($data) && (is_null($userId) || $userId != $data[0]['id']));
}