dxe / adb

Activist Database Project
11 stars 5 forks source link

Log out after 12 hours #205

Open alexsapps opened 8 months ago

alexsapps commented 8 months ago

After a Google account is disabled or password reset, we need ADB access to expire in less than 30 days which is the current behavior. However, this change avoids expiring the session too quickly in order to avoid data loss until we can set up sessions to renew automatically before they expire if the user is still working or verify this is already happening.

alexsapps commented 6 months ago

Still thinking about this. In an emergency we could shut down the ADB and start it back up with different keys, and I don't want someone to be in the middle of taking attendance without any indication that their session is expiring imminently.

alexsapps commented 3 months ago

(In addition to rotating the server key in the event of an emergency) Maybe we can make the cookie expire at 5AM to avoid people getting signed out while trying to do something like taking attendance. Might update this PR for that eventually.

ChatGPT and I co-authored this function (not tested)

package main

import (
    "fmt"
    "time"
)

func next5AMPTAfter24Hours() time.Time {
    // Get the current time in PT
    loc, err := time.LoadLocation("America/Los_Angeles")
    if err != nil {
        panic(err)
    }
    now := time.Now().In(loc)

    // Calculate 5 AM PT tomorrow
    tomorrow := now.AddDate(0, 0, 1)
    tomorrow5AM := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 5, 0, 0, 0, loc)

    // If tomorrow's 5 AM PT is more than 24 hours from now, use it
    if tomorrow5AM.After(now.Add(24 * time.Hour)) {
        return tomorrow5AM
    }

    // Otherwise, calculate 5 AM PT the day after tomorrow
    dayAfterTomorrow := now.AddDate(0, 0, 2)
    dayAfterTomorrow5AM := time.Date(dayAfterTomorrow.Year(), dayAfterTomorrow.Month(), dayAfterTomorrow.Day(), 5, 0, 0, 0, loc)

    return dayAfterTomorrow5AM
}