views:

26

answers:

1

Good morning,

for an existing web application I need to implement "time based login constraints". It means that for each user, later maybe each group, I can define timeslots when they are (not) allowed to log in into the system. As all data for the application is stored in database tables, I need to somehow create a way to model this idea in that way.

My first approach, I will try to explain it here:

  • Create a tree of login constraints (called "timeslots") with the main "categories", like "workday", "weekend", "public holiday", etc. on the top level, which are in a "sorted" order (meaning "public holiday" has a higher priority than "weekday")
  • for each top level node create subnodes, which have a finer timespan, like "monday", "tuesday", ...
  • below that, create an "hour" level: 0, 1, 2, ..., 23. No further details are necessary.
  • set every member to "allowed" by default
  • For every member of the system create a 1:n relationship member:timeslots which defines constraints, e.g. a member A may have A:monday-forbidden and A:tuesday-forbidden
  • Do a depth-first search at every login and check if the member has a constraint. Why a depth first search? Well, I thought that it may be that a member has the rules:

A:monday->forbidden, A:monday-10->allowed, A:mondey-11->allowed

So a login on monday at 12:30 would fail, but one at 10:30 succeed.

For performance reasons I could break the relational database paradigm and set a flag for every entry in the member-to-timeslots-table which is set to true if the member has information set for "finer" timeslots, but that's a second step.

Is this model in principle a good idea? Are there existing models?

Thanks.

A: 

Wow. That sounds way more complicated than I'd want to deal with. I'd just create a table like this:

Allowed_Login_Times

  • Weekday_Start
  • Weekday_End
  • Saturday_Start
  • Satruday_End
  • Sunday_Start
  • Sunday_End
  • Holiday_Start
  • Holiday_End

Each column would be an int from 0 to 23 representing the hour.

I'd let the application decide what hour it was and which column should be checked.

Your solution is more flexible, but I can't imagine trying to create an admin GUI to maintain the data.

Jeremy Stein
Well, the hour constraint must be possible to be defined per user.
DaDaDom
Right, so either you add a user_id (or group_id) column to this table, or you add these columns to your user table.
Jeremy Stein