###login types:
- username with pin
- username with pin linked to srnd account
- srnd-linked rfid
- srnd-linked rfid with pin
- guest account (special username 'guest'; not entered into database)
##sqlite create table statement
CREATE TABLE accounts (id integer primary key, username text unique, srnd text unique, pin text, pin_on_rfid boolean, balance real,
CHECK (username IS NOT 'guest'),
CHECK (srnd NOTNULL OR username NOTNULL),
CHECK (CASE WHEN username NOTNULL THEN pin NOTNULL END),
CHECK ((srnd NOTNULL) IS (balance ISNULL)),
CHECK ((username NOTNULL AND srnd NOTNULL) IS (pin_on_rfid NOTNULL)))
Notes:
- user must have srnd or username (or both)
- if user has username, user must have pin, otherwise it is optional
- iff account linked to srnd, local balance is null
- iff user has srnd and username, pin_on_rfid is not null
examples:
- (id 0, username "asdf", srnd null, pin "0023", pin_on_rfid null, balance 0)
- (id 1, username null, srnd "edj", pin null, pin_on_rfid null, balance null)
- (id 2, username null, srnd "george.matter", pin "4767", pin_on_rfid null, balance null)
- (id 3, username "shelvacu", srnd "michael.tebbs", pin "2993", pin_on_rfid false, balance null)
- (id 4, username "jizzyjugs", srnd "blaise.ritchie", pin "7331", pin_on_rfid true, balance null)
##JSON communication changes new "log in" request:
{
"type" : "log in",
"username" : "asdf",
("pin" : "0023")
# pin will only be null if username is 'guest'
}
new "log in success" response to replace "log in" response:
{
"type" : "log in succcess"
"account" : {
("username" : ~"MadhATT3R6"),
# or
("srnd" : ~"george.matter"),
"balance" : ~4.25,
# if username and srnd
("pin_on_rfid" : ~true)
}
}
new "log in failure" response:
{
"type" : "log in failure",
"reason" : <"username"|"pin"|"rfid">
}
new "create account" request:
{
"type" : "create account",
"account" : {
"username" : "adsf",
"pin" : "0652"
}
}
new "create failure" response:
{
"type" : "create failure",
"reason" : <"duplicate"|"pin">
}
new "set" request:
{
"type" : "set",
"key" : <"pin"|"pin_on_rfid">,
"value" : ~"new value"
}
"set success" and "set failure" responses:
{
"type" : "set success",
"key" : <"pin"|"pin_on_rfid">,
"value" : ~"new value"
}
{
"type" : "set failure",
"key" : <"pin"|"pin_on_rfid">,
"value" : ~"old value"
}
"link" requests:
{
"type" : "link rfid"
}
{
"type" : "link username",
"username" : ~"MadhATTER6",
"pin" : ~"1234"
}
"link" responses:
{
"type" : "link rfid " + <"success"|"failure"|"timeout">,
# if success
("srnd" : ~"george.matter"),
# if failure
("reason" : "rfid")
}
{
"type" : "link username " + <"success"|"failure">,
# if failure
("reason" : <"username"|"pin">)
}