Don't let the same user register more than once
1 files changed, 15 insertions(+), 9 deletions(-) M bulletin.rkt
M bulletin.rkt => bulletin.rkt +15 -9
@@ 73,15 73,21 @@ [password (hash-ref params 'password)] [input (hash-ref params 'input)]) (if (auth username password) (let* ([token (crypto-random-bytes 128)] [token (bytes->hex-string token)]) (displayln (format "~a is voting! (~a)" username input)) (hash-set! _peers (string->symbol token) (hasheq 'input input 'username username)) ; send the token that the peer will use for further ; authorization (response/jsexpr token)) ; check if username is already present (if (for/or ([(_ peer) _peers]) (equal? username (hash-ref peer 'username))) (response/jsexpr "That username is already in use" #:code 403) (let* ([token (crypto-random-bytes 128)] [token (bytes->hex-string token)]) (displayln (format "~a is voting! (~a)" username input)) (hash-set! _peers (string->symbol token) (hasheq 'input input 'username username)) ; send the token that the peer will use for further ; authorization (response/jsexpr token))) (response/jsexpr "Bad Login" #:code 400)))