Restrict login by timezone mod - Posted (1192 Views)
Senior Member
StephenD
Posts: 1044
1044
G'day, haven't posted here in a long time but still read what's happening almost every day...
Looking to build a mod to restrict certain users from logging in initially outside normal hours but then for different times.
Thinking I should add a TZ_ID to the FORUM_MEMBERS table linked to 2 new tables FORUM_TIMEZONE and FORUM_TIMEZONE_DEF

FORUM_TIMEZONE:
TZ_ID = integer, identity seed, primary key
TZ_DESCRIPTION

FORUM_TIMEZONE_DEF:
TZ_ID = integer
DAYOFWEEK = integer
START = Integer 4 digits eg 0800
STOP = Integer 4 digits eg 1700

Then some code to check the server day of week/time against user on login against their allowed timezone and throw them back with a 'Outside Allowed hours access violation' message.
Anyone see any issues by going this route or is there an easier way. Anyone done something similar already?<
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Advanced Member
Carefree
Posts: 4224
4224
Why split it into 2 tables and what's the purpose of a TZ description? Assuming that you want to use different times for weekdays vs weekends (else why DOW?), you'd only need five fields.

To do what you want, I'd make a single new table; include TZ_ID, WEEKDAY_START, WEEKDAY_STOP, WEEKEND_START & WEEKEND_STOP. I'd then add TZ_ID to the member table & put it into the "register.asp" & "inc_profile.asp" files.
Then for implementation, you would query the (TZ_ID field from the member table) & the (TZ's allowed times from the TZ table) in both "inc_header.asp" & "inc_header_short.asp"; compare them to current time and deny/grant access accordingly.<
Posted
Advanced Member
Etymon
Posts: 2396
2396
Couldn't the users change the time setting on their computers and also change the timezone setting in the profiles to emulate an allowed time?<
Posted
Advanced Member
Carefree
Posts: 4224
4224
Changing the time or time zone on their computers would be meaningless if the server is comparing the start/stop times to YOUR computer's time. An ability to edit the time zone in their profiles would be necessary for anyone who travels, otherwise they would have to recalculate their time based upon the location they lived when they originally registered.
It would be a lot easier to restrict their login times based upon the first letter of their user name. Then you wouldn't need any additional table or variables.<
Posted
Advanced Member
Etymon
Posts: 2396
2396
I think I misunderstood the problem then.
Do you mean something like this (putting this in offline terms):

The office is located on the east coast (USA). The timezone there is EST. Anyone who calls there after 5 PM EST, regardless of where they are calling from, will get an automated reply from the answering machine because no one is there after 5 PM EST.
Is that what you mean by saying the time is based off of YOUR computer's time?
<
Posted
Senior Member
StephenD
Posts: 1044
1044
Yes, I want to restrict by Server Time regardless of where the user is. Initially 1 Timezone (perhaps timezone is not a good descriptor) for normal office hours but I can see they will want additional timezones set up for users authorised for overtime and on weekends which is why I suggested the 2 tables - 1 with description.<
Posted
Advanced Member
Etymon
Posts: 2396
2396
Have you thought about setting up these types of users into UserGroups? It sounds like you are dealing with at least three types of users. I think there is some code here on the forums for you to parse out the UserGroup IDs that you are wanting. I mean that after you create each UserGroup you can use the code to identify the UserGroup. I'll look for it. I think I know where it is.
Here. Try these three links to research it:
http://forum.snitz.com/forum/topic.asp?TOPIC_ID=65531&SearchTerms=getGroupMembership(
http://forum.snitz.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=63846&SearchTerms=getGroupMembership(
http://forum.snitz.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=62521&SearchTerms=getGroupMembership(

Just a mockup of the thought-process could be like this:

Code:
if the sever time is between this and that, then ' Normal business hours
Allow the "Everyone is Allowed" UserGroup elseif the server time is between this and that, then ' Overtime business hours
Allow the "Overtime is Allowed" UserGroup elseif the server time is between this and that, then ' Weekend business hours
Allow the "Weekends are Allowed" UserGroup end if

Above is just a thought-process, you could code it differently to suite your needs of course.
- If worker A is allowed to work overtime and weekends as well as normal hours, then place worker A in all three UserGroups (normal hours, overtime, and weekends).
- If worker B is allowed to work overtime as well as normal business hours but not weekends, then place worker B in just two of the UserGroups (normal hours, and weekends).
- If worker C is only allowed to work normal hours, then place worker C only in one UserGroup (normal hours).
I think I would try that approach first if it were me trying to figure it out for my site. <
Posted
Senior Member
StephenD
Posts: 1044
1044
Ok, I ended up with 3 timezones. 1 = 24/7 Unrestricted
2 = 0800 - 1730 Mon-Fri
99 = No Access

I added a TZ int field (default value of 1) to Forum_Members and changed pop_profile to allow Admins to change this variable.
I created a new table FORUM_TZ_DEF

With fields:
TZ_ID int
TZ_START_DAY smallint
TZ_STOP_DAY smallint
TZ_START_TIME varchar(4)
TZ_STOP_TIME varchar(4)

I populated the table like so:
Code:

	1	1	1	0000	2400
1 2 2 0000 2400
1 3 3 0000 2400
1 4 4 0000 2400
1 5 5 0000 2400
1 6 6 0000 2400
1 7 7 0000 2400
2 2 2 0800 1730
2 3 3 0800 1730
2 4 4 0800 1730
2 5 5 0800 1730
2 6 6 0800 1730


Now working on the code for inc_header and inc_header_short. Need to query vb WeekDay with Hour(Time) + Minute(Time) against this table using the TZ_ID from the member table then allow access.
If Weekday for TZ_ID exists then ... check between start/stop times. <
 
You Must enter a message