Hi,
I have the following situation:
There is a user object and a userSettings object. Between these two objects there is a 1-1 relationship.
In userSettings i have two fields: activeStartDate and activeEndDate.
In my portal i created the login page for User object.
I need a validation based on activeStartDate and activeEndDate from userSettings, if the current date is not between these two values then the login to fail and a message to be shown.
How can i do this validation?
Thanks!
I tried Pavel's suggestion and it works! The object script is working on the USER object too.
As mentioned, I created an object script with "On Login" timing and used "throw" to display the validation error. The original script was also modified to make sure the validation will be applied portal login only.
if (rbv_api.isPortal()) { var today = new Date(rbv_api.getCurrentDate()).setHours(0,0,0,0), start_date = new Date('{!R114277826.start_date}').setHours(0,0,0,0), end_date = new Date('{!R114277826.end_date}').setHours(0,0,0,0); rbv_api.println("today:" + new Date(today)); rbv_api.println("start_date:" + new Date(start_date)); rbv_api.println("end_date:" + new Date(end_date)); if (start_date > today || end_date < today) throw "Account is only valid from {!R114277826.start_date} to {!R114277826.end_date}"; }
Hi Hortensia,
You can use "is Active" field (automatically generated when "portal visitor" attribute is enabled) to allow/deny portal users from logging in. An inactive user who will get "Your account is inactive or not activated yet." validation error when they login to the portal.
However, you will need to transfer your portal fields to a non-USER object. The "is Active" field doesn't work on USER object - I will file a defect for this.
You also need a scheduled process to update the "is Active" field. This can be accomplish this by creating a data maintenance batch job that will run daily. Below is the code to automatically check/uncheck the field:
var today = new Date(rbv_api.getCurrentDate()).setHours(0,0,0,0), start_date = new Date('{!start_date}').setHours(0,0,0,0), end_date = new Date('{!end_date}').setHours(0,0,0,0); rbv_api.println("today:" + new Date(today)); rbv_api.println("start_date:" + new Date(start_date)); rbv_api.println("end_date:" + new Date(end_date)); isActivValue = (start_date <= today && end_date >= today) ? true : false; rbv_api.println("isActivValue:" + isActivValue); rbv_api.setFieldValue("user_settings", {!id}, "isActive", isActivValue);
Regards,
Godfrey
You can create Object Script trigger and assign it "On Login" option. In that trigger perform any validation you need and throw JavaScript exception if you want to stop user from login.
Example:
if ({!role#id}!=90) throw "LOGIN DISABLED";
That will block any non-admin user from login.
However this approach will not work quite well due to bug in our code. This will be fixed: PSC00319165
In the mean time try assigning "No Access" role to blocked users.
I tried Pavel's suggestion and it works! The object script is working on the USER object too.
As mentioned, I created an object script with "On Login" timing and used "throw" to display the validation error. The original script was also modified to make sure the validation will be applied portal login only.
if (rbv_api.isPortal()) { var today = new Date(rbv_api.getCurrentDate()).setHours(0,0,0,0), start_date = new Date('{!R114277826.start_date}').setHours(0,0,0,0), end_date = new Date('{!R114277826.end_date}').setHours(0,0,0,0); rbv_api.println("today:" + new Date(today)); rbv_api.println("start_date:" + new Date(start_date)); rbv_api.println("end_date:" + new Date(end_date)); if (start_date > today || end_date < today) throw "Account is only valid from {!R114277826.start_date} to {!R114277826.end_date}"; }
Thanks Godfrey, it works yours suggestion!
Only one more thing: it gives me the message but also the line number where is the throw statement.
Is there a way that the line number to not be shown?
You can use the code below on your login page as a workaround solution to this problem:
<style> #rb_infoMessageText { display: none; } </style> <script> $(function (){ var infomessage = $('#rb_infoMessageText').html(); var endPhrase_index = infomessage.indexOf('line #'); alert(endPhrase_index) if(endPhrase_index > 0) $('#rb_infoMessageText').html( infomessage.substring(0, endPhrase_index - 1) ); $('#rb_infoMessageText').show(); }); </script>
I will let you know if there is a plan to remove the line # when using throw.
Godfrey