<![CDATA[ Update Username - My Forums]]> https://forums.modx.com/thread/?thread=103843 <![CDATA[Update Username]]> https://forums.modx.com/thread/103843/update-username?page=2#dis-post-558507
I included the username field in the UpdateProfile form but changes are not being saved. No errors, the value just stays the same. Works fine when editing in the Manager Menu > Users > User.
[[!UpdateProfile?
	&preHooks=`FullName`
	&excludeExtended=`email:required:email,login-updprof-btn,mediaFolder`
	&validate=`username:required:minLength=`^6^`,
		email:required:email`
	&useExtended=`0`
]]

<form action="[[~[[*id]]]]" method="post">
    [[+login.update_success:is=`1`:then=`[[%login.profile_updated? &namespace=`login` &topic=`updateprofile`]]`]]

    <label for="username">[[!%login.username]] [[!+error.username]]</label>
    <input type="text" name="username" id="username" value="[[+username]]">
    …
</form>
]]>
todd.b May 12, 2018, 06:34 AM https://forums.modx.com/thread/103843/update-username?page=2#dis-post-558507
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username?page=2#dis-post-558577 ]]> nuan88 May 15, 2018, 04:53 PM https://forums.modx.com/thread/103843/update-username?page=2#dis-post-558577 <![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558571
$profile = $modx->user->getOne('Profile');


Suppose, though, that you only have the user ID for some other user and want to send an email. There's no need to get the user object unless you also need the username.

$profile = $modx->getObject('modUserProfile', array('internalKey' => $userId));
$email = $profile->get('email');
$fullName = $profile->get('fullname');


If you do need the username, you can add this step at the end:

$user = $profile->getOne('User');
$username = $user->get('username');


If you only have the ID and you want both the modUser and modUserProfile objects, a faster way is to use $modx->getObjectGraph(), which will only make one query to the database, but that's more complicated.]]>
BobRay May 15, 2018, 04:35 AM https://forums.modx.com/thread/103843/update-username#dis-post-558571
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558568
But this sentence makes me wonder

If you have a user ID you can get the user's email, for example, without retrieving the modUser object since the modUserProfile contains the user ID in its internalKey field.

is this a two way street, or is the one easier or better to get than the other? You chose one way over the other, is it preferable for some reason? Or you are just emphasizing the independence of the two objects?]]>
nuan88 May 15, 2018, 12:45 AM https://forums.modx.com/thread/103843/update-username#dis-post-558568
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558532

I don't really know the thinking behind the separation of the modUser and modUserProfile object into separate objects in two different tables. It may be speed-related, since the modUser object is quite small. Also, given a user ID, you can pull either the modUser object or the modUserProfile independently, depending on what you need. If you have a user ID you can get the user's email, for example, without retrieving the modUser object since the modUserProfile contains the user ID in its internalKey field.

Another possibility is that in the very early Etomite days, the modUser object was all there was. When they realized that people needed more user information in the DB, they created a separate table for the extra data rather than modifying the modUser object, and included the extended field so that you could put whatever you needed into the user profile.

For info on what's where:

modUser: https://bobsguides.com/modx-object-quick-reference.html#modUser

modUserProfile: https://bobsguides.com/modx-object-quick-reference.html#modUserProfile]]>
BobRay May 14, 2018, 04:37 AM https://forums.modx.com/thread/103843/update-username#dis-post-558532
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558523
Users are identified by their first name, not their full name or username.

Thanks for your explanation and yes, I see your point. There often seems to be at least one solution to any problem.]]>
todd.b May 13, 2018, 04:56 AM https://forums.modx.com/thread/103843/update-username#dis-post-558523
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558521
I don't know what your site looks like but when you build pages you can let users be identified by fullname rather than username and then the lack of changing would be less serious.

Eko, I think the honest answer is that Modx doesn't really deal with user issues, its one of the gaps in the system. Even the extended profile in a JSON is probably not optimal. Keep in mind a lot of sites don't need users at all.

However there are tools like BobRay's classExtender that solve these problems pretty easily. Remember Modx is supposed to be a contained system, where ALL customization should happen outside that core, never hack the core because you can always modify an extra, snippet or other tool. So its supposed to be compact.

If it handled these issues, it would be great, but what would happen when you didn't like those default behaviors?

So, users are an extra module by necessary. Doesn't make it easier to climb that hill, though. But, most of the tools we need are out there.]]>
nuan88 May 12, 2018, 09:23 PM https://forums.modx.com/thread/103843/update-username#dis-post-558521
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558520
Thank you.]]>
todd.b May 12, 2018, 09:12 PM https://forums.modx.com/thread/103843/update-username#dis-post-558520
<![CDATA[Re: Update Username]]> https://forums.modx.com/thread/103843/update-username#dis-post-558519
Going back to your first reply about modUser and modUserProfile, is there a specific reason why two different objects would be used for the user profile? Could it be a security thing?

Not knowing how or why MODX was designed the way it is it seems, with my limited understanding, that the user profile info would all fall under the same umbrella (object), so to speak.]]>
todd.b May 12, 2018, 07:26 PM https://forums.modx.com/thread/103843/update-username#dis-post-558519
<![CDATA[Re: Update Username (Best Answer)]]> https://forums.modx.com/thread/103843/update-username#dis-post-558518
The hook would look something like this (untested):

$submittedName = $hook->getValue('username');

if ( (!empty($submittedName) ) && ($submittedName !== $modx->user->get('username') ) ) {
   $modx->user->set('username', trim($submittedName) );
   $modx->user->save();
}





]]>
BobRay May 12, 2018, 06:10 PM https://forums.modx.com/thread/103843/update-username#dis-post-558518