Ok, I added the following to SaveUserProfile (1.3.1):
// Update username - Paul
//escape proposed username
$newusername = $modx->db->escape($_POST['username']);
//Check if used
$newusernameres = $modx->db->select("username",$web_users,"`username`='".$newusername."'");
if(!$modx->db->getRecordCount($newusernameres)) // Not already used
{
// Get current username
$usernameres = $modx->db->select("username",$web_users,"`id`='".$internalKey."'");
if($modx->db->getRecordCount($usernameres)) // If this user exists - how could it not?
{
$userrow = $modx->db->getRow($usernameres);
if($userrow['username'] != $newusername)
{
$modx->db->update("`username`='".$newusername."'",$web_users,"`id`='".$internalKey."'");
}
}
}
else
{
$this->FormatMessage($this->LanguageArray[7]);
return;
}
You can add it where you like - it bails if the username already exists that you are trying to set to, so if you’d prefer to test this before any other updates, then put it at the beginning. I put it last.
I expect that the SaveUserProfile function will be updated at some point, so that all the checks happen first, and then all the updates happen once all the checks are complete.