Hey all,
I’m trying to generate a confirmUrl link within my custom snippet to send to a user to activate his/her account. I’m not using the snippet ‘Register’ to create the user’s account but I have coded it within my snippet. I have successfully created the account and assigned the user to it correct resource group but the confirmUrl does not activate the account. I’m not sure where I’m going wrong, here is my code below.
$count = $modx->getCount('modUser', array ('username' => $employee_email));
if ($count> 0 ) {
// this user exists!
$modx->setPlaceholder('fi.validation_error_message','Error!!! This user has enrolled by another employer.');
return false;
}
$user = $modx->newObject('modUser');
// set the username and password
$user->set('username', $employee_email );
$password = $ms->randomPassword();
$hook->setValue("password",$password);
//$user->set('password', $password );
$modx->getService('registry', 'registry.modRegistry');
$modx->registry->addRegister('login', 'registry.modFileRegister');
$modx->registry->login->connect();
$modx->registry->login->subscribe('/useractivation/');
$modx->registry->login->send('/useractivation/',array($user->get('username') => $password),array(
'ttl' => (180*60),
));
$user->set('cachepwd',md5($password));
// save
$user->save();
// create a profile
$profile = $modx->newObject('modUserProfile');
// initialize the fields
$profile->set('fullname',$employee_fullname);
$profile->set('email' ,$employee_email);
$profile->set('dob',$dob);
$profile->set('gender',$gender);
$profile->set('phone' ,$phone);
$extended['fname'] = $employee_fname;
$extended['lname'] = $employee_lname;
$extended['enrolled'] = 1;
$profile->set('extended', $extended);
// add a profile to the user
$user->addOne($profile);
$user->set('active', 0);
// save
$profile->save();
$user->save();
$group = $modx->getObject('modUserGroup', array('name' => 'Employees'));
$groupMember = $modx->newObject('modUserGroupMember');
$groupMember->set('user_group', $group->get('id'));
$groupMember->set('role',1); // 1 is a membership with the Member role
$groups[] = $groupMember;
// add user to groups
$user->addMany($groups);
$user->save();
$confirmParams['lp'] = urlencode(base64_encode($password));
$confirmParams['lu'] = urlencode(base64_encode($employee_email));
$confirmUrl = $modx->makeUrl(20,'',$confirmParams,'full');
$hook->setValue("confirmUrl",$confirmUrl);