MODX Login Chunk for isLoggedIn - authentication

I am using isLoggedIn Script for a members only site. It seems to work nearly perfect besides one thing: I am using the normal Chunk (lgnLoginTpl) which comes with the complete Login package. There in the form an action with an url/domain etc. is needed but i need it dynamic. This means if you enter an protected page you are redirected to login and after logging in back to protected page. I have more than one protected page so it must be some kind of "intelligent".
&redirectToPrior=1 is also not working in this case.
Can anybody help and tell me how to set up lgnLoginTpl correctly to get isLoggedIn script to work as I need?

It sounds like the first part of your problem, redirecting to login page when needed, is solved simply by setting the correct "unauthorized page" in your system settings. &redirectToPrior should be what you need, by "not working in this case", do you mean it's not working at all or not redirecting back to the previous page, regardless of what it was?
If it is the fact that it simply isn't working, thats probably because it relies on $_SERVER['HTTP_REFERER']`, ie a php server variable telling the page which page redirected to it. This will however not always be set depending mostly on browser. A workaround i've implemented is to place a little snippet at the top of the Unathorized page
$_SERVER['HTTP_REFERER'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
This will "manually" set the HTTP_REFERER to the current URL, which is what you want, as the URL doesn't change after you've been redirected from a protected page to the unauthorized URL. And then you can use the &redirectToPrior param of the Login? snippet.

Thank you for your answer.
I tried some things and I now it seems I have only one problem which is that I am redirected to unauthorized page (login page), that works fine but after logging in I am not redirected to the right protected page.
I made to different pages test1 and test2. If I am loggin in I am always redirected to test1.
test1 login -> test1
test2 login -> test1
It seems &redirectToPrior=1 is overriden by &loginResourceId=12. I am calling the plugin with following code:
[[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &logoutResourceId=`0` &loginResourceId=`12` &redirectToPrior=`1`]]
Removing &loginResourceId=12 (ID 12 is test1) doesn't work at all and redirects my to my 404 page (home).
&loginResourceId=12 should be removed but what to insert instead?

Related

How to Redirect Users to the Login Page when Trying to Access an Unpublished Content Page in Drupal 7

I am trying to have users accessing some draft content (unpublished contents) links so they can log in and get redirected to these links. Once they click on the link, they will get redirected to the login page and once they log in with their credentials they will get redirected to the desired page. What happens is that when they click on any links they get redirected to the homepage.
I tried to add a rule in the /admin/config/workflow/rules but I was unable to figure out the conditions and actions of the proper event I need to add in order to have my users get redirected to login and then straight to the desired page (either published or unpublished it doesn't matter).
I am using Drupal 7.67 and mostly UI interface on a Windows 10 machine.
The easiest way I can think of is create function like this.
function modulename_redirect_when_unpublished(){
//Check if user is in rigth place (viewing nodes).
if(arg(0) == 'node' && arg(1)){
//Load this node.
$node = node_load(arg(1));
//Check if node status is different than published, and if user is not logged.
if($node->status != 1 && !user_is_logged_in()){
//Prepare destination to come back.
$destination = arg(0) . '/' . arg(1);
//Go to login page with destination saved.
drupal_goto('user/login', array('query' => array('destination' => $destination )));
}
}
}
You can pass any path in "destination" parameter in GET and after login it will redirect you there.
Only question is where to put this function. For tests purpose I called it in one of my custom module hook_init, but you can put it somewhere else, just be sure it will be called on 'node/%' pages - you mentioned something about using Rules, it could be done that way but I think it's overcomplicated to create custom rule just for one case to fire this particular function, so I suggest you to put this code in some hook_init like I did.
I've tested it on Drupal 7.57.

Selenium Chromedriver call to logout page not working

I want to write an automated test with Selenium using Chromedriver and Behat.
This scenario in question should go to a page, register a user, logout and register another user.
Now the problem is, on the website in question, after registration you get an annoying overlay, so that the logout button is not reachable anymore. I can either make the test fill out the overlay and complete it properly, which will take much more effort, or try to logout some other way.
My idea was to simply go to the domain again with /?event=logout added which normally works to log out the current user. However when I do this in the automation it fails, apparently because of a bad http response code.
Is it not possible to use a url like this with Selenium? Anyone have an idea?
You can achieve this with Selenium using a site that makes GET requests. So you can go to URL http://requestmaker.com/, fill the www.website.com in the Request URL, and 'event=logout' in the Request data, then click "Submit".
It's a bit hacky, so I would prefer using a GET request directly in the code, depending on your programming language... Something like so:
https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/
Some options would be:
Navigate to URL to logout and try to hide the modal via jQuery/javascript
After registration navigate to homepage and see if the modal is there and if you can logout as you should
Clear session and navigate to the page you need
Pick one of them.

Redirecting URL assigned to Home Tab on Plone

On Plone, I am looking at establishing a User Group with an initial login page (collective.onlogin) that leads to what I hope will be the new Home Page. How do I change the Home Tab to reflect this once the authorised user has moved past the LogIn page. Currently, the home tab reflects and returns to the login page - string${globals_view/navigationRootUrl}
Where string:${globals_view/navigationRootUrl} is specified you may specify other expressions. In this case, you'll probably wish to create a BrowserView or Python Script that returns the path you want, since it sounds like there may be some real logic. Then, call that view or script rather than globals_view/navigationRootUrl.
Found that if I de-activated collective.onlogin, went to the "Change content item as default view ..." and selected the home page that I wanted, then reactivated collective.onlogin I would get what I wanted. The login page is still very vanilla, but that can wait for another day. Hope this helps the next person.

Yii-User and Yii-eauth integration

I am trying to put together an application using yii-user and yii-eauth extensions but I am coming up short. When I create a new webapp and install eauth I can get it to work fine so I know that I am not doing anything wrong on that end. I think the problem lies with my urls. This is a demo of what it is supposed to be like: http://nodge.ru/yii-eauth/demo/login. When someone clicks on say google it should bring you to the google sign in page but on my application I am getting a 404 error that states "The system is unable to find the requested action "login"." The url for this is user/user/login/service/google_oauth whereas the url should read user/login/service/google_oauth. Upon typing this into the browser manually I am redirected to the right page.
So I took a look into the EAuthWidget.php class to see if I could find out where it was getting that extra "user" from but I could not figure it out. I think it may have something to do with the fact that I have this in the user module which is in the /modules/user directory in my webapp. I also tried to use the URLManager to point to the right address but with no luck.
Does anyone have any similar experiences setting this up? Or any suggestions?
You just need to change the widget initialization code in your view(namely change the action property of the widget), somewhat like this:
<h2>Do you already have an account on one of these sites? Click the logo to log in with it here:</h2>
<?php
$this->widget('ext.eauth.EAuthWidget', array('action' => 'login'));
?>
Just to add, keep in mind that this action depends on which view you are including this widget, if the view is protected/views/site/login.php (which is yii's default site login view) then action should be able to go to the yii-user module's login action, so it'll be : 'action'=>'/user/login' , however if you are including this widget in yii-user's protected/modules/user/views/user/login.php then the action will be 'login' as already mentioned.

Redirect After Registration in Drupal

Any one know how to go back to the "last page" after a user is presented the login screen and chooses to create a new account?
Basically the sequence is this:
User tries to get to protected content
Redirected to login page
If he logs in he is redirected to original page
If he chooses "create new account" and fills it out, he is redirected to the home page
How do we get him automatically redirected to the original page (not a static page).
There are several ways to go about this. The most straight-forward is to have a login link somewhere in the navigation that appends the destination to the url. The code for this is something like:
<?php
if (user_is_anonymous()) {
$link = l(t('Login'), 'user/login', array('query' => drupal_get_destination()));
}
?>
You can also set a custom access denied page at admin/settings/error-reporting that could either go to a callback that outputs the above code, or to a simple php node that outputs that code.
Additionally, the user login block provided with Drupal core uses the same method to redirect a successful login back to the originating page.
Edit: Note that the above methods will rarely work for registration, because there are more steps involved there. Specifically, when a user needs to verify an email address, passing the originating destination along via the email would involve modifying the core user registration process.
It will potentially still work on a site configured to not verify email addresses. The idea then would be to provide 2 links: 1 for login and the other for registration, both passing along destination information.
LoginToboggan may also be worth pursuing, although it doesn't yet offer the exact registration feature you're looking for.
straight php would be to include a header of this form:
<?php header("Location: " . $_SERVER['HTTP_REFERER']); ?>
for more information refer to the php manual
EDIT:
you can also include a hidden field in your form and set it to
$url = $_SERVER['PHP_SELF']; // or HTTP_REFERER depending on the setup
include the header code snipped to your registration form.