Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (56 sloc) 2.532 kb
ff457d0 0.1.0 release
Dave Byrne authored
1 (ns foreclojure.register
5e6af1b Anthony Grimes Upgrade dependencies and move to Clojure 1.4.
Raynes authored
2 (:require [noir.session :as session]
04d150f Alex McNamara Cleaned up namespace declarations.
amcnamara authored
3 [ring.util.response :as response])
4 (:import [org.jasypt.util.password StrongPasswordEncryptor])
5e6af1b Anthony Grimes Upgrade dependencies and move to Clojure 1.4.
Raynes authored
5 (:use [hiccup.form :only [form-to text-field password-field]]
ba91988 Alex McNamara Made ns bindings amalloy-friendly.
amcnamara authored
6 [compojure.core :only [defroutes GET POST]]
502d1f6 Alan Malloy Fix email regex, refactor it into a single place
amalloy authored
7 [foreclojure.utils :only [form-row assuming flash-error plausible-email?]]
6504415 Alex McNamara Initial template update.
amcnamara authored
8 [foreclojure.template :only [def-page]]
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
9 [foreclojure.messages :only [err-msg]]
ba91988 Alex McNamara Made ns bindings amalloy-friendly.
amcnamara authored
10 [somnium.congomongo :only [insert! fetch-one]]))
b381469 Alan Malloy Add an 'assuming' macro to reduce some nesting and repetition
amalloy authored
11
ff457d0 0.1.0 release
Dave Byrne authored
12 (def-page register-page []
fd74d9b Alan Malloy Add a bunch more <title>s
amalloy authored
13 {:title "4clojure &ndash; Register"
14 :content
15 (list
16 [:div.error (session/flash-get :error)]
17 (form-to [:post "/register"]
18 [:table
19 (map form-row
20 [[text-field :user "Username (4-13 chars.)" (session/flash-get :user)]
21 [password-field :pwd "Password (7+ chars.)"]
22 [password-field :repeat-pwd "Repeat Password"]
23 [text-field :email "Email" (session/flash-get :email)]])
24 [:tr
25 [:td [:button {:type "submit"} "Register"]]]]))})
ff457d0 0.1.0 release
Dave Byrne authored
26
27 (defn do-register [user pwd repeat-pwd email]
a457638 Anthony Grimes Usernames should be case insensitive.
Raynes authored
28 (let [lower-user (.toLowerCase user)]
29 (assuming [(nil? (fetch-one :users :where {:user lower-user}))
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
30 (err-msg "settings.user-exists"),
a457638 Anthony Grimes Usernames should be case insensitive.
Raynes authored
31 (< 3 (.length lower-user) 14)
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
32 (err-msg "settings.uname-size"),
a457638 Anthony Grimes Usernames should be case insensitive.
Raynes authored
33 (= lower-user
34 (first (re-seq #"[A-Za-z0-9_]+" lower-user)))
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
35 (err-msg "settings.uname-alphanum")
95b3371 Alan Malloy No maximum password length. Feel free to use gettysburg address if you w...
amalloy authored
36 (< 6 (.length pwd))
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
37 (err-msg "settings.pwd-size"),
a457638 Anthony Grimes Usernames should be case insensitive.
Raynes authored
38 (= pwd repeat-pwd)
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
39 (err-msg "settings.pwd-match"),
502d1f6 Alan Malloy Fix email regex, refactor it into a single place
amalloy authored
40 (plausible-email? email)
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
41 (err-msg "settings.email-invalid")
b355b7f Creighton Kirkendall Added user email validation and duplicate detection
ckirkendall authored
42 (nil? (fetch-one :users :where {:email email}))
a2b4eba Creighton Kirkendall changed the err-msgs function to err-msg
ckirkendall authored
43 (err-msg "settings.email-exists")]
89ce06c Alan Malloy Someone messed up indentation of my (assuming) form. If it was you, get ...
amalloy authored
44 (do
45 (insert! :users
46 {:user lower-user
47 :pwd (.encryptPassword (StrongPasswordEncryptor.) pwd)
48 :email email})
5e6af1b Anthony Grimes Upgrade dependencies and move to Clojure 1.4.
Raynes authored
49 (session/put! :user lower-user)
89ce06c Alan Malloy Someone messed up indentation of my (assuming) form. If it was you, get ...
amalloy authored
50 (response/redirect "/"))
03d54ca Keeping username and email address values after bad registration
David Davis authored
51 (do
52 (session/flash-put! :user user)
53 (session/flash-put! :email email)
4647a3f Alan Malloy Reverse argument order to flash-error and flash-msg
amalloy authored
54 (flash-error "/register" why)))))
38f7bdb Anthony Grimes Separate routes into modular and easy digestable chunks.
Raynes authored
55
56 (defroutes register-routes
57 (GET "/register" [] (register-page))
58 (POST "/register" {{:strs [user pwd repeat-pwd email]} :form-params}
162e005 Move images css and scripts into the proper directories
Carin Meier authored
59 (do-register user pwd repeat-pwd email)))
Something went wrong with that request. Please try again.