The following JavaScript code will check if the current user needs to be signed out during specific hours.
Set start_time and end_time for the hours users can use the Formyoula app in a 24h format.
Please add below JavaScript code on your Formyoula form deployed to your users.
( function() {
// Check if JavaScript already loaded
if ( !window[ 'formyoula_js_set_interval_to_check_user_signout_outside_specific_hours' ] ) {
// Set time format
var time_format = 'hh:mm:ss';
// Set the start and end time
var start_time = moment( '08:00:00', time_format );
var end_time = moment( '20:00:00', time_format );
// Start Interval
window[ 'formyoula_js_set_interval_to_check_user_signout_outside_specific_hours' ] = setInterval( function() {
// Check if Formyoula is signed in
if ( window.formyoula.user ) {
// Run main check function
check_user_signout_outside_specific_hours();
}
}, 1000 * 60 * 30 ); // END Interval
// Function for checking if user is logged in between specific hours
function check_user_signout_outside_specific_hours() {
// Check if user is logged in between specific hours
if ( !moment().isBetween( start_time, end_time ) ) {
// Trigger signout
window.formyoula.event_trigger( 'sync:clear_all', {} );
window.formyoula.event_trigger( 'login:main', {} );
// Remove user details
delete window.formyoula.user;
}
}
}
} )();
For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂