summaryrefslogtreecommitdiffstats
path: root/add-user.scm
blob: 9799bf5df0fc4d69ab821fc4bcf5c9b7b6290a6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(import
  scheme (chicken base)
  (chicken process-context)
  sqlite3
  crypt
  srfi-1
)

(define params (argv))
(define username (second params))
(define password (third params))
(define password-hash (crypt password))

(define db (open-database (or (get-environment-variable "DB_FILE") "/tmp/54itter.db")))

(execute db "CREATE TABLE IF NOT EXISTS users (
                user_id TEXT PRIMARY KEY,
                pw_hash TEXT,
                created_at DATETIME default current_timestamp
            )")

(execute db "INSERT INTO users
                    (user_id, pw_hash)
                    VALUES (?, ?)"
                username password-hash)
(finalize! db)

(print "Created user " username)