Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions orbit/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def usr_setpwdhash_username(usr): return _set(USR_SETPWDHASH_USERNAME, usr)


USR_GET = """
SELECT id, username, pwdhash, student_id
SELECT username, pwdhash, student_id
FROM users;
""".strip()
def usr_get(): return _get(USR_GET)


USR_GETBY_USERNAME = """
SELECT id, username, pwdhash, student_id
SELECT username, pwdhash, student_id
FROM users
WHERE username = ?;
""".strip()
Expand All @@ -138,16 +138,9 @@ def usr_getby_username(usn): return _get(USR_GETBY_USERNAME, usn)
def reg_ins(tpl): return _set(REG_INS, tpl)


REG_GETBY_STUID = """
SELECT registration_id, username, password
FROM newusers
WHERE student_id = ?;
""".strip()
def reg_getby_stuid(sid): return _get(REG_GETBY_STUID, sid)


REG_DELBY_REGID = """
REG_GETDEL_BY_STUID = """
DELETE FROM newusers
WHERE registration_id = ?;
""".strip()
def reg_delby_regid(rid): return _set(REG_DELBY_REGID, rid)
WHERE student_id = ?
RETURNING username, password;
"""
def reg_get_and_del_by_stuid(sid): return _set(REG_GETDEL_BY_STUID, sid)
1 change: 0 additions & 1 deletion orbit/hyperspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def nou(u):


USR_FMT = """
Orbit ID : {}
Username : {}
Hashed Password : {}
Student ID : {}
Expand Down
20 changes: 9 additions & 11 deletions orbit/init-db.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE users (
id integer primary key,
username string UNIQUE NOT NULL,
pwdhash string NOT NULL,
student_id integer);
username text UNIQUE NOT NULL,
pwdhash text NOT NULL,
student_id text UNIQUE) STRICT;
CREATE TABLE sessions (
token string PRIMARY KEY,
username string UNIQUE NOT NULL,
expiry string NOT NULL);
token text PRIMARY KEY,
username text UNIQUE NOT NULL,
expiry real NOT NULL) STRICT;
CREATE TABLE newusers (
registration_id integer primary key,
student_id string UNIQUE NOT NULL,
username string UNIQUE NOT NULL,
password string NOT NULL);
student_id text UNIQUE NOT NULL,
username text UNIQUE NOT NULL,
password text NOT NULL) STRICT;
COMMIT;
5 changes: 2 additions & 3 deletions orbit/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,10 @@ def form_respond():
if not (student_id := rocket.body_args_query('student_id')):
rocket.msg('you must provide a student id')
return form_respond()
if not (registration_data := db.reg_getby_stuid(student_id)[0]):
if not (registration_data := db.reg_get_and_del_by_stuid(student_id)[0]):
rocket.msg('no such student')
return form_respond()
(regid, username, password) = registration_data
db.reg_delby_regid(regid)
(username, password) = registration_data
rocket.msg('welcome to the classroom')
return rocket.respond((register_response % {
'username': username,
Expand Down
75 changes: 38 additions & 37 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,43 +80,44 @@ ${DOCKER} volume export singularity_orbit-db > test/orbit_orig.tar

# Import an empty orbit db with no users or sessions
xxd -r <<- 'EOF' | gunzip | ${DOCKER} volume import singularity_orbit-db -
00000000: 1f8b 0800 0000 0000 0003 edda 4d4f db30 ............MO.0
00000010: 18c0 f104 4adf a4b6 f430 e584 e6e3 9010 ....J....0......
00000020: 4da0 c061 9ab4 0ef5 80d6 7583 b507 4e55 M..a......u...NU
00000030: 503d 88a0 098b 5301 c7f2 51f6 7da6 1df6 P=....S...Q.}...
00000040: 6576 5c12 7005 4cdd 3a6d 685a f4ff 49b1 ev\.p.L.:mhZ..I.
00000050: 9de4 8965 3f71 0f56 1a84 475e b43e 3c32 ...e?q.V..G^.><2
00000060: 1e91 1ddb 6e36 d3da 7950 db8e 9394 86d3 ....n6..yP......
00000070: dcb6 3737 eded 1ddb 316c c7de b19b 86b0 ..77....1l......
00000080: 1f73 50da 5845 6e18 0fe5 4ffb b16f 4ceb .sP.XEn...O..oL.
00000090: ffc4 fbfd 8e17 49f1 2108 476e 2436 8d65 ......I.!.Gn$6.e
000000a0: c334 8d97 42c4 b7cc f828 dd09 5d8c 8fdc .4..B....(..]...
000000b0: 9d73 738e ee4d 633d fc54 a97d 338a 95ba .ss..Mc=.T.}3...
000000c0: 51db aa7d ae3a b55c f56b a55e 352a 5ffe Q..}.:.\.k.^5*_.
000000d0: e234 0000 0000 e0f7 4d9e e70b d6ca 8a79 .4......M......y
000000e0: bd17 b947 67d2 9717 6325 43a5 ebc2 ee41 ...Gg...c%C....A
000000f0: bbd5 6b8b 5eeb 55a7 2df4 55f1 ac5c 0ae5 ..k.^.U.-.U..\..
00000100: b1a7 a2d0 8dbc c01f 7843 e1f9 913c 96a1 ........xC...<..
00000110: 380f bd91 1b5e 8953 79b5 562e a968 3c94 8....^.Sy.V..h<.
00000120: 7e94 04c4 c19e 7f2c fadd bdfd 7e5b 74df ~......,....~[t.
00000130: f644 b7df e9c4 3149 97be 3b92 b323 ce5d .D....1I..;..#.]
00000140: a52e 8270 da87 beb5 da28 e6ad dd15 d3f0 ...p.....(......
00000150: fca1 bc54 1fcf e2bd ddc0 1d47 417a 3ed0 ...T.......GAz>.
00000160: c31d 6ce8 56a9 5198 eb01 47b7 8a93 a78b ..l.V.Q...G.....
00000170: 37f9 a9a7 f951 52a9 78c2 4ad7 b97b f9d1 7....QR.x.J..{..
00000180: 57e3 fc88 5b51 702a 7d3d ee77 077b 6f5a W...[Qp*}=.w.{oZ
00000190: 0787 e275 fb70 6d1a f1cb e9eb 4079 79ee ...u.pm.....@yy.
000001a0: c589 fd21 074b 3f9b 921e d260 43b7 f28d ...!.K?....`C...
000001b0: dc5c 0f38 bab5 3479 6216 2ccb 32af 4b69 .\.8..4yb.,.2.Ki
000001c0: 0ed2 c4a4 c5c2 bdd9 4f97 c6cc d530 c79b ........O....0..
000001d0: be18 9eb8 eae4 e124 efaf a4db ce57 5717 .......$.....WW.
000001e0: f2d6 0b6b d644 6edf 645a 257b f962 b2dc ...k.Dn.dZ%{.b..
000001f0: 2b49 b1fc 4f7f 7100 0000 0000 e091 9593 +I..O.q.........
00000200: 82fd 3f00 0000 0000 99c6 f77f 0000 0000 ..?.............
00000210: 00b2 8fef ff00 0000 0000 641f fb7f 0000 ..........d.....
00000220: 0000 00b2 8fff ff03 0000 0000 907d 7cff .............}|.
00000230: 0700 0000 0020 fbd8 ff03 0000 0000 0000 ..... ..........
00000240: d9f5 1df3 6b21 9400 9600 00 ....k!.....
00000000: 1f8b 0800 0000 0000 0003 edda c14e db30 .............N.0
00000010: 18c0 7107 4a4b 2b85 224d 5a2e 20f9 3824 ..q.JK+."MZ. .8$
00000020: 4493 8c72 9b34 56f5 80d6 b151 ca81 5395 D..r.4V....Q..S.
00000030: aa9e 8806 0d8b 5395 9da6 ee51 7887 5df6 ......S....Qx.].
00000040: 0e7b 8d5d f602 3b2e cd30 a29b 4a91 36b4 .{.]..;..0..J.6.
00000050: 2dfa ffa4 d84e 6cb7 feec e460 2551 dc0b -....Nl....`%Q..
00000060: 93ad 7e4f dc23 37b5 b3bd 9de5 de4f b9eb ..~O.#7......O..
00000070: f993 5478 db3b 9eef d7fd ba5b 17ae e7ba ..Tx.;.....[....
00000080: 754f 48f7 3e07 650c 7512 c452 8af4 3f6f uOH.>.e.u..R..?o
00000090: 6d37 affe 3f75 78d0 0a13 255f 47f1 5990 m7..?ux...%_G.Y.
000000a0: c8c7 6255 5896 789a ce87 1056 7a54 6e34 ..bUX.x....VzTn4
000000b0: 5d4c 8fc2 8d73 eb0e 3f6f 89ad f8d2 ae7e ]L...s..?o.....~
000000c0: 1365 7b4d 54d7 aa9f ab97 2bce cad7 954f .e{MT.....+....O
000000d0: f69a fdc5 fef8 0703 0100 0000 80df 307e ..............0~
000000e0: 582a 39eb ebd6 f87d 12f4 4ed5 408d 865a X*9....}..N.@..Z
000000f0: c5da e4cb 8d76 73b7 d394 9ddd 67ad a634 .....vs.....g..4
00000100: 57e5 a34a 5927 c3be 1a24 ddb0 2f13 7591 W..JY'...$../.u.
00000110: c8a3 fdbd 83a3 a6dc 7fd9 91fb 47ad d666 ............G..f
00000120: a53c 693a 08ce d4ac faf3 40eb 5114 5ff5 .<i:......@.Q._.
00000130: 3715 1bf2 b0d3 de6b 746a e5a2 d358 b744 7......ktj...X.D
00000140: 38e8 ab0b fdf6 34dd c175 8361 1265 e75d 8.....4..u.a.e.]
00000150: 3392 ae6f 4a95 daf2 9d3a 78a6 541e cb42 3..oJ....:x.T..B
00000160: 16fa 8707 59e8 5a69 1d46 036d f2a5 a9d0 ....Y.Zi.F.m....
00000170: cdd5 3474 7925 89de a8c1 8fc1 bf6a efbd ..4ty%.......j..
00000180: d86d 1fcb e7cd e3cd ebfa 39f1 9b66 eae2 .m........9..f..
00000190: 3c8c dfc9 5805 a7bf 4e42 f1b6 98cc 98ba <...X...NB......
000001a0: be29 956a 4b77 eae0 9952 71bc 6895 1cc7 .).jKw...Rq.h...
000001b0: b1c6 2a9b 846c 66b2 6461 2afc eb65 9fbb ..*..lf.da*..e..
000001c0: a8a3 fe49 a04f a6d7 7473 d6ed 62e2 dc58 ...I.O..ts..b..X
000001d0: 2c3a 4f9c 59c3 be5a e92c 2b6c 2ccc 6fea ,:O.Y..Z.,+l,.o.
000001e0: 65d9 642f bf3c b9c7 ed49 b2fa 571f 3300 e.d/.<...I..W.3.
000001f0: 0000 0000 70cf b217 fcec ff01 0000 0000 ....p...........
00000200: c835 f6ff 0000 0000 00e4 1fdf ff03 0000 .5..............
00000210: 0000 907f bcff 0700 0000 0020 ffd8 ff03 ........... ....
00000220: 0000 0000 907f 7cff 0f00 0000 0040 fef1 ......|......@..
00000230: fe1f 0000 0000 80fc 63ff 0f00 0000 0000 ........c.......
00000240: 0000 0000 0000 0000 0000 0000 0000 ffa6 ................
00000250: ef58 8985 d900 c800 00 .X.......
EOF

# Restore the old orbit db after testing completes
Expand Down