RE: Hook to override login portal for adding OTP field in login.jsp

Subeena Razeed, modified 8 Years ago. New Member Posts: 15 Join Date: 1/5/15 Recent Posts
HI All,
My requirement is to add an OTP field in the login page. Login credentials should be validated again external database table. Once the validation is successful OTP field should be displayed in the login page with the Login button. On click of Login button OTP field should be validated and user should be redirected to respective community based on the user role.
Please suggest how to implement this.

I have tried an ajax call to validate again external database after entering username and password. But in this case all the in-built validations of liferay has to be rewritten/customized.

Thanks
Anonymous Anonymous, modified 8 Years ago. Regular Member Posts: 127 Join Date: 9/16/19 Recent Posts
Hello ,

You have to use struts action of liferay ex: <struts-action-impl>com.test.demo.LogincustomAction</struts-action-impl>.
when user enters email and password redirect to a custom JSP ex: return "/portal/customLogin.jsp"; page where you can show a field to enter OTP . After that you can cross check the OTP if it match then call the original struts action to login success.
ex: originalStrutsPortletAction.processAction( originalStrutsPortletAction, portletConfig, actionRequest,actionResponse);


Thanks,
Enayath
Liferay User, modified 8 Years ago. New Member Posts: 15 Join Date: 1/5/15 Recent Posts
Thank you Enayath for your suggestion.
I have implemented my requirement as below.
1. Overriden liferay's login.jsp and included OTP field(hidden by default)
2. My custom class will implement Authenticator and extends BaseStrutsPortletAction(Struts Action class ).
3. Once user enter credentials and click on Sign in, authenticateByEmailAddress() method will be called for validating user credentials with external db and returns success/ failure.
4. If the validation is success, user will be landed on login.jsp where I have put condition to show the OTP field.
5. After OTP field is entered and clicked on Submit button, processAction is called and redirected to the respective page based on the roles.

Please let me know If you find any issues on this implementation.
Anonymous Anonymous, modified 8 Years ago. Regular Member Posts: 127 Join Date: 9/16/19 Recent Posts
Hello ,

So after submitting the correct OTP only user can successfully login to the portal.
In this case the user has already entered email and password hence just cross check the email exists or not and No need of redirecting again to login.jsp.
go for a custom jsp and take the email id and password entered into custom jsp so that you can pass email , password and OTP to struts action again (you can refer any blog to return to a custom jsp page ).

when you get the all the 3 field values is OTP matches allow user to login by calling :
return originalStrutsPortletAction.render(
null, portletConfig, renderRequest, renderResponse);

so that it will redirect to page, the above steps may help to reduce the customization of Hook as well .

if you want to apply particular rediection after login you can trigger a post login event .


Regards,
Enayath
thumbnail
Kiran Yalavali, modified 6 Years ago. Regular Member Posts: 175 Join Date: 10/15/14 Recent Posts
Hi  Subeena Razeed,



Did you find answer to this? I'm also same requirement and looking for solution.



Regards,
​​​​​​​Kiran.