Expand my Community achievements bar.

SOLVED

Login Redirection in CQ

Avatar

Former Community Member

Hi,

We have a process where we want users to be redirected to different pages after they login based on their interaction with the website.

Current all our users are redirected to page which is configured in Login Selector Handler. Can we override this.

We are logging in the users (from form j_custom_security_check) and credentials via Ajax calls.  We have window.location.href after successful login and that seems to be ignored by CQ.

Please advise

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi,

The Login Selector Authentication Handler allows you to specify a different login page based on the content path. It sounds like this isn't what you are trying to do. Instead, you want to redirect the user to a different location after login.

One way to do this is to pass a request parameter named resource with the path you want to redirect after login.

Another way is to handle the login in AJAX and then do the redirect manually. If you want to use the approach (which it sounds like you do), be sure to pass the j_validate parameter. See http://sling.apache.org/documentation/the-sling-engine/authentication/authentication-authenticationh...

Regards,

Justin

View solution in original post

4 Replies

Avatar

Employee

You can write a custom auth handler and in requestCredentials method, you can redirect appropriately.

Avatar

Correct answer by
Employee

Hi,

The Login Selector Authentication Handler allows you to specify a different login page based on the content path. It sounds like this isn't what you are trying to do. Instead, you want to redirect the user to a different location after login.

One way to do this is to pass a request parameter named resource with the path you want to redirect after login.

Another way is to handle the login in AJAX and then do the redirect manually. If you want to use the approach (which it sounds like you do), be sure to pass the j_validate parameter. See http://sling.apache.org/documentation/the-sling-engine/authentication/authentication-authenticationh...

Regards,

Justin

Avatar

Former Community Member

justin_at_adobe wrote...

Hi,

The Login Selector Authentication Handler allows you to specify a different login page based on the content path. It sounds like this isn't what you are trying to do. Instead, you want to redirect the user to a different location after login.

One way to do this is to pass a request parameter named resource with the path you want to redirect after login.

Another way is to handle the login in AJAX and then do the redirect manually. If you want to use the approach (which it sounds like you do), be sure to pass the j_validate parameter. See http://sling.apache.org/documentation/the-sling-engine/authentication/authentication-authenticationh...

Regards,

Justin

 

Hi Justin,

You are right. I am trying to use the second approach. I had passed j_validate true already and login is happening fine. My login is a lightbox and i do an Ajax call within the lightbox. On success for most cases i have to refresh the page so i was trying to refresh using window.location.reload() event. The login returns success and after this line is executed, i get UserName or password not valid on the page but the user is still logged in. In one or two use case i have to redirect the user back to the page they were accessing before they were asked to login.

Any ideas or pointers would be appreciated.

Thanks.

Avatar

Former Community Member

justin_at_adobe wrote...

Hi,

The Login Selector Authentication Handler allows you to specify a different login page based on the content path. It sounds like this isn't what you are trying to do. Instead, you want to redirect the user to a different location after login.

One way to do this is to pass a request parameter named resource with the path you want to redirect after login.

Another way is to handle the login in AJAX and then do the redirect manually. If you want to use the approach (which it sounds like you do), be sure to pass the j_validate parameter. See http://sling.apache.org/documentation/the-sling-engine/authentication/authentication-authenticationh...

Regards,

Justin

 

In success method of jquery i have got window.top.location.href="http://localhost:4503/abcd/pqrs.html" and once login is successful i am always redirected to the page which is configured within the DAY CQ login selector handler. In the URL bar i see resource=%2Fcontent%2Fmysite%2Fmypage.html&$$login$$=%24%24login%24%24&j_reason=INVALID_CREDENTIALS. The credentials are valid. I checked and within AuthUtil.sendRedirect method this string is formed. I called AuthUtil.sendRedirect method with targetResource within Authentication succeeded method and my authenticationSuccedded method return true but nothing really happens.

But if i have configured an external domain in window.top.location.href then redirect is working fine. Any ideas will be appreciated.