<commit_before>(ns foreclojure.register
  (:import [org.jasypt.util.password StrongPasswordEncryptor])
  (:use [foreclojure.utils]
        [somnium.congomongo]
        (hiccup [form-helpers]))
  (:require [sandbar.stateful-session :as session]
            (ring.util [response :as response])))

(defn form-row [[type name info]]
  [:tr
   [:td (label name info)]
   [:td (type name)]])

(def-page register-page []
  [:div {:class "error"} (session/flash-get :error)]
  (form-to [:post "/register"]
           [:table
            (map form-row
                 [[text-field :user "Username (4-12 chars.)"]
                  [password-field :pwd "Password (7-12 chars.)"]
                  [password-field :repeat-pwd "<PASSWORD>"]
                  [text-field :email "Email"]])
            [:tr
             [:td (submit-button {:type "image" :src "/register.png"} "Register")]]]))

(defn do-register [user pwd repeat-pwd email]
  (assuming [(nil? (fetch-one :users :where {:user user}))
             "User already exists",
             (< 3 (.length user) 13)
             "Username must be 4-12 characters long",
             (< 6 (.length pwd) 13)
             "Password must be 7-12 characters long",
             (= pwd repeat-pwd)
             "Passwords don't match",
             (not (empty? email))
             "Please enter a valid email address"]
    (do
      (insert! :users
               {:user user
                :pwd (.encryptPassword (StrongPasswordEncryptor.) pwd)
                :email email})
      (session/session-put! :user user)
      (response/redirect "/"))
    (flash-error why "/register")))<commit_msg>User names must be alphanumeric<commit_after>(ns foreclojure.register
  (:import [org.jasypt.util.password StrongPasswordEncryptor])
  (:use [foreclojure.utils]
        [somnium.congomongo]
        (hiccup [form-helpers]))
  (:require [sandbar.stateful-session :as session]
            (ring.util [response :as response])))

(defn form-row [[type name info]]
  [:tr
   [:td (label name info)]
   [:td (type name)]])

(def-page register-page []
  [:div {:class "error"} (session/flash-get :error)]
  (form-to [:post "/register"]
           [:table
            (map form-row
                 [[text-field :user "Username (4-12 chars.)"]
                  [password-field :pwd "Password (7-12 chars.)"]
                  [password-field :repeat-pwd "Repeat Password"]
                  [text-field :email "Email"]])
            [:tr
             [:td (submit-button {:type "image" :src "/register.png"} "Register")]]]))

(defn do-register [user pwd repeat-pwd email]
  (assuming [(nil? (fetch-one :users :where {:user user}))
             "User already exists",
             (< 3 (.length user) 13)
             "Username must be 4-12 characters long",
	     (= user
		(first (re-seq #"[A-Za-z0-9_]+" user)))
	     "Username must be alphanumeric"
	     (< 6 (.length pwd) 13)
	     "Password must be 7-12 characters long",
             (= pwd repeat-pwd)
             "Passwords don't match",
             (not (empty? email))
             "Please enter a valid email address"]
    (do
      (insert! :users
               {:user user
                :pwd (.encryptPassword (StrongPasswordEncryptor.) pwd)
                :email email})
      (session/session-put! :user user)
      (response/redirect "/"))
    (flash-error why "/register")))
{'fraction_non_alphanumeric': 0.1519099792715428, 'fraction_numerical': 0.011252591057151318, 'mean_word_length': 2.037769784172662, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, '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': '1755590', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1004, 'n_words': 285}