if (!$user) { /* create a new rpxUser */ $user = $modx->newObject('rpxUser'); $user->fromArray(array( 'username' => $rpxProfile['preferredUsername'] ,'active' => true ,'remote_key' => $rpxIdentifier ,'remote_data' => $rpxProfile )); $profile = $modx->newObject('modUserProfile'); $profile->fromArray(array( 'email' => isset($rpxProfile['email']) ? $rpxProfile['email'] : '' ,'fullname' => isset($rpxProfile['displayName']) ? $rpxProfile['displayName'] : (isset($rpxProfile['preferredUsername']) ? $rpxProfile['preferredUsername'] : $rpxIdentifier) )); $user->addOne($profile, 'Profile'); $saved = $user->save(); }
<?php if ($user && ($user instanceof rpxUser) && $saved) { $modx->log(modX::LOG_LEVEL_INFO, 'RPXNow logging in remote user into contexts: ' . print_r($contexts, true)); foreach ($contexts as $context) { $user->addSessionContext($context); } } ?>
$corePath = $modx->getOption('login.core_path',$scriptProperties,$modx->getOption('core_path',null,MODX_CORE_PATH).'components/login/'); $login = $modx->getService('login','Login',$corePath.'model/login/',$scriptProperties); if (!is_object($login) || !($login instanceof Login)) return ''; $output = ''; $modx->lexicon->load('login:default'); /* setup default properties */ $preHooks = $modx->getOption('preHooks',$scriptProperties,''); $loginTpl = $modx->getOption('loginTpl',$scriptProperties,'lgnLoginTpl'); $logoutTpl = $modx->getOption('logoutTpl',$scriptProperties,'lgnLogoutTpl'); $loginMsg = $modx->getOption('loginMsg',$scriptProperties,''); $logoutMsg = $modx->getOption('logoutMsg',$scriptProperties,''); $tplType = $modx->getOption('tplType',$scriptProperties,'modChunk'); $actionKey = $modx->getOption('actionKey',$scriptProperties,'service'); $loginKey = $modx->getOption('loginKey',$scriptProperties,'login'); $logoutKey = $modx->getOption('logoutKey',$scriptProperties,'logout'); $errorPrefix = $modx->getOption('errorPrefix',$scriptProperties,'error'); $errTpl = $modx->getOption('errTpl',$scriptProperties,'lgnErrTpl'); $errTplType = $modx->getOption('errTplType',$scriptProperties,'modChunk'); $rememberMeKey = $modx->getOption('rememberMeKey',$scriptProperties,'rememberme'); $loginContext = isset($_REQUEST['login_context']) && !empty($_REQUEST['login_context']) ? $_REQUEST['login_context'] : $modx->context->get('key'); $contexts = !empty($scriptProperties['contexts']) ? $scriptProperties['contexts'] : ''; $contexts = !empty($_REQUEST['add_contexts']) ? $_REQUEST['add_contexts'] : $contexts; //echo '<h4>here, authenticated = '.$authenticated.'</h4>'; $authenticated = $modx->user->isAuthenticated($loginContext); //echo '<h4>here, authenticated = '.$authenticated.' context = '.$loginContext.'</h4>';
It’s not undefefined; it’s inherited from the xPDO class, which modX extends.
So if I look in the doco:
http://rtfm.modx.com/display/revolution20/modX
$modx->log is not defined.
No, JanRain is different from the Login snippet. You are not passing username/password ever. JanRain handles that and returns either a successful or unsuccessful result. All you have to do is add the user data (minus the password, since you never need the password locally), capture any external data you want to, and simple addSessionContext for whatever contexts you want the user to be logged into when JanRain returns a successful result.
What I understand from your quoted extract of the snippet is:
if $user passes your test (is a user, and part of the rpxuser group and $saved (not sure what that is checking))
Then do this undefined log function which I am guessing has something to do with identifying what contexts they have access to, so similar to modUser::getSessionContexts ??
Then for each of those contexts you addSessionContext to the user.
The addSessionContext does that then actually then "log them in" so that if you then do a user logged in check they will now be seen as logged in whereas before the addSessionContext they aren’t?
Thanks for your help on this, just trying to get my head around what is actually happening here.
So if I check their unique id from Janrain which I have stored and their username and that checks against my user list in my modx_users table then I can simply define a user of that username and addSessionContext of the appropriate context for them and they will then be "logged in"?
No, JanRain is different from the Login snippet. You are not passing username/password ever. JanRain handles that and returns either a successful or unsuccessful result. All you have to do is add the user data (minus the password, since you never need the password locally), capture any external data you want to, and simple addSessionContext for whatever contexts you want the user to be logged into when JanRain returns a successful result.
Yep, just addSessionContext() for each context you want them authenticated in.
Now if that username exists in my database I then need to check if the unique id matches otherwise it is another user with that username and I have to deal with that separately - creating another user for example. So I can do that check. If it matches OK then all I need to do is addSessionContext for that user?
That is then effectively "logging them in" so to speak so that modx recognises that user as logged in if I then want to pull other info from their profile (ie I use JanRain to log them in but they also have the option to update their profile with other information that I can then use to personalise some of the pages for them depending on the preferences they set there - so on other pages I would then be able to use $modx->user type commands if needed?).