<commit_before>(ns crunsher.communication.auth
  (:require [ajax.core :refer [POST]]
            [goog.crypt.base64 :as gtfo]
            [crunsher.communication.utils :as com]
            [crunsher.config :as config]
            [crunsher.debug :as debug]
            [crunsher.utils.common :as lib]
            [crunsher.communication.main :as com]
            [crunsher.communication.utils :as clib]
            ))

(defn success-login
  "Callback function when login was successful. Set attributes of user."
  [response]
  (let [res (com/process-response response)]
    (println "Successfully logged in." res)))

(defn ajax-login
  "Get cleaned data and send ajax request."
  [nickname password]
  (let [url (str (:base config/api) "login")]
    (POST (clib/make-url url)
          {:body            (clib/clj->json {:nickname nickname
                                            :password password})
           :handler         success-login
           :error-handler   com/error-handler
           :response-format :json
           :headers         {"Content-Type" "application/json"}
           :keywords?       true})))

(defn login
  "Use login form data, validate it and send ajax request."
  [nickname password]
  (when (and
          (pos? (count nickname))
          (pos? (count password)))
    (ajax-login nickname password)))<commit_msg>Add auth function<commit_after>(ns crunsher.communication.auth
  (:require [ajax.core :refer [POST]]
            [crunsher.communication.utils :as com]
            [crunsher.config :as config]
            [crunsher.communication.main :as com]
            [crunsher.communication.utils :as clib]))

(defn success-login
  "Callback function when login was successful. Set attributes of user."
  [response]
  (let [res (com/process-response response)]
    (println "Successfully logged in." res)))

(defn ajax-login
  "Get cleaned data and send ajax request."
  [email password location]
  (let [url (:login config/api)]
    (POST (clib/make-url url)
          {:body            (clib/clj->json {:email email
                                             :password password
                                             :location location})
           :handler         success-login
           :error-handler   com/error-handler
           :response-format :json
           :headers         {"Content-Type" "application/json"}
           :keywords?       true})))

(defn login
  "Use login form data, validate it and send ajax request."
  [email password location]
  (when (and
          (pos? (count email))
          (pos? (count password))
          (pos? (count location)))
    (ajax-login email password location)))
{'fraction_non_alphanumeric': 0.11094452773613193, 'fraction_numerical': 0.0007496251874062968, 'mean_word_length': 2.005630630630631, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3945240', 'n_tokens_mistral': 753, 'n_tokens_neox': 716, 'n_words': 220}