-
- 119 Posts
Hi!
I'm building an AJAX login and I'm wondering if the Login snippet has hooks for being used as a service. Perhaps like, [[~idOfPageWithLoginSnippet]]?service=login&user=username&pass=password or something similar? Is this possible or will I need to write my own snippet to do this?
Thanks!
Have you tried your own suggestion? Without testing, I reckon that would work, tho you'll need to refresh the origin page after that to see the effects.
If it doesnt work, use n ajax post instead of get; might help.
-
- 24,544 Posts
I think that should work. I couldn't find an example of it for login, but this will log a user out:
<a href="[[~[[$loginPageId]]]]&service=logout">
so I'm guessing it would be something like:
<a href="[[~[[$loginPageId]]]]&service=login;&username='username';&password='password'">
It might be easier to just log the user in directly if you have the user object with:
$modx->user =& $user;
$modx->getUser();
$user->addSessionContext('web');
I'm not sure which would be more secure.
-
- 255 Posts
The &service=logout redirects the user to the logut page (not quite the "ajaxy" feel of retaining the current page w/o reload). I have not tried to pass the current resource ID as the &redirectTo argument in the call though it could work on login and logout service calls but it would reload the existing resource I imagine. Again sort of defeats the purpose of an Ajax call.
I would be interested in the outcome if anyone tries it though.
I have done login with an ajax login resource passing the data back and forth via json (which I didn't really need to do) and that works fine, but takes a bit more setup. IIRC, Splittingred posted something a while back on how to set up ajax resources but I couldn't find it.
-
- 24,544 Posts
You can log the user out and stay on the same page with this:
$modx->user->removeSessionContext('web');
If the personalize snippet appears before the logout snippet in the page's code, I would expect it to see the user as still being logged in, since the user doesn't get "logged out" until the logout snippet has run.