Quote from: modxlearner123 at Aug 27, 2010, 11:27 PM
if the snippet is being used with the register form of Login.Rester and the user hasn’t logged in yet then when you say:If not logged in, you’d have to get the user with $modx->getObject() based on the username unless all the user info you want is available in the hook
the we could retrieve the username like this?:
$userName = $modx->getObject('username')
I don’t know what I was thinking there. If the user isn’t logged in, there’s no use trying to get the username from the DB because MODx has no idea who the user is.
If the register form has been filled out and submitted, the username should be available as $_REQUEST[’username’], but I’m not sure you’d want to do anything with it because the user hasn’t been activated by clicking on the link in the activation email and might never do so (especially if it’s a spam bot of some kind).
On the Confirm Registration page, a snippet could do something like this:
<?php
$username = base64_decode(urldecode($_REQUEST['lu']));
/* validate we have correct user */
$user = $modx->getObject('modUser',array('username' => $username));
if ($user) {
/* yes we have */
/* your code here */
}
?>
FYI, $modx->getObject() always requires the type of object you want it to get as the first argument. The second argument contains the criteria for finding the object (although it can be just an ID):
<?php
$user = $modx->getObject('modUser', array('username'=>'JoeUser'));
//or, if you know the user's ID:
// $user = $modx->getObject('modUser',12);
if ($user) {
$username = $user->get('username');
} else {
/* no such user */
}