Added optional Discourse SSO.
This commit is contained in:
parent
5527c1eb91
commit
54da04763f
8 changed files with 337 additions and 8 deletions
26
db.go
26
db.go
|
|
@ -140,6 +140,11 @@ func migrate(db *sql.DB) error {
|
|||
department_id INTEGER NOT NULL REFERENCES departments(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (participant_id, department_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sso_nonces (
|
||||
nonce TEXT PRIMARY KEY,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
|
@ -1350,6 +1355,27 @@ func (app *App) listOpenShiftsForDept(deptID int) ([]Shift, error) {
|
|||
ORDER BY s.day, s.position, s.start_time`, deptID)
|
||||
}
|
||||
|
||||
// --- SSO Nonces ---
|
||||
|
||||
func (app *App) createSSONonce(nonce string) error {
|
||||
_, err := app.db.Exec(`INSERT INTO sso_nonces (nonce) VALUES (?)`, nonce)
|
||||
return err
|
||||
}
|
||||
|
||||
func (app *App) consumeSSONonce(nonce string) (bool, error) {
|
||||
res, err := app.db.Exec(
|
||||
`DELETE FROM sso_nonces WHERE nonce = ? AND created_at > datetime('now', '-10 minutes')`, nonce)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (app *App) cleanExpiredNonces() {
|
||||
app.db.Exec(`DELETE FROM sso_nonces WHERE created_at < datetime('now', '-10 minutes')`)
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
func now() string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue