<commit_before>(ns crumb.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
            [net.cgrand.enlive-html :as html]
            [crumb.db-service :as db]))

(html/deftemplate create-account-template "create-account.html"
  [messages]
  [:div.messages] (html/html-content (reduce str (map #(str "<p>" %1 "</p>") messages))))

(defn attempt-create-user-account
  [username]
  (let [usr-exists (db/user-exists? username)
        result {:user-created false :messages []}]
    (if usr-exists
      (assoc result :messages ["This username is already taken."])
      (do
        (db/create-user-account username)
        (assoc result :user-created true)))))

(defn create-user-account
  [username]
  (let [usr-response (attempt-create-user-account username)]
    (if (:user-created usr-response)
      "GREAT"
      (create-account-template (:messages usr-response)))))

(defroutes app-routes
  (GET "/" [] "Hello World")
  (GET "/create-account" []  (create-account-template []))
  (POST "/create-account" {{username :username} :params} (create-user-account username))<commit_msg>added a wee message<commit_after>(ns crumb.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
            [net.cgrand.enlive-html :as html]
            [crumb.db-service :as db]))

(html/deftemplate create-account-template "create-account.html"
  [messages]
  [:div.messages] (html/html-content (reduce str (map #(str "<p>" %1 "</p>") messages))))

(defn attempt-create-user-account
  [username]
  (let [usr-exists (db/user-exists? username)
        result {:user-created false :messages ["User created!"]}]
    (if usr-exists
      (assoc result :messages ["This username is already taken."])
      (do
        (db/create-user-account username)
        (assoc result :user-created true)))))

(defn create-user-account
  [username]
  (let [usr-response (attempt-create-user-account username)]
    (if (:user-created usr-response)
      "GREAT"
      (create-account-template (:messages usr-response)))))

(defroutes app-routes
  (GET "/" [] "Hello World")
  (GET "/create-account" []  (create-account-template []))
  (POST "/create-account" {{username :username} :params} (create-user-account username))
{'fraction_non_alphanumeric': 0.16217337204479468, 'fraction_numerical': 0.0008295313148071339, 'mean_word_length': 3.299465240641711, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5178474', 'n_tokens_mistral': 777, 'n_tokens_neox': 770, 'n_words': 184}