#lang racket/base

; Add a new user to the database

(require
  "src/notepad/user.rkt"
  "src/pages/notepad.rkt" ; To open the database
  )

(displayln "Adding a new user.")
; Ask for user name
(displayln "Enter the user name:")
(define name (read-line))
(when (eof-object? name)
  (exit 1))

; Check if user already exists
(when (get-user-by-name name)
  (displayln (string-append "User " name " already exists!"))
  (exit 2))

; Ask for user password
(displayln "Enter the user password:")
(define password (read-line))
(when (eof-object? name)
  (exit 1))

; Add user to db
(void
  (new-user name password))
(displayln (string-append "User " name " added."))
