")
(def closing "\n\nSincerely,\n\nYour Anxiety\n\nhttp://anxietybox.com // http://twitter.com/anxietyboxbot")
(defn mailgun-send
"Post an email to the mailgun gateway."
[form]
(info form)
(client/post mailgun-uri
{:basic-auth mailgun-auth
:throw-entire-message? true
:form-params (merge {:from from-email} form)}))
(defn send-confirmation
""
[box]
(info box)
(mailgun-send { :to (:email box)
:subject "Confirmation requested"
:text (str "Dear " (:name box) ",
\nYou just signed up for Anxietybox.com. Click here to confirm your email:
\n\thttp://anxietybox.com/activate/" (:confirm box) "
\nIf you didn't sign up, ignore this email." closing)}))
(defn send-reminder [box]
(mailgun-send { :to (:email box)
:subject "Account information"
:text (str "Dear " (:name box) ",
\nClick here to delete your account:
\n\thttp://anxietybox.com/delete/" (:confirm box) "
\nYou can start a new account any time." closing)}))
(defn anxiety-text [box]
(str "Dear " (:name box) ",\n\n"
(bot/compose
(if (:anxieties box) (:description (rand-nth (:anxieties box))))
(if (:reply box) (:description (rand-nth (:replies box)))))
closing
"\n\nP.S. Click here to delete your account:"
"\n\thttp://anxietybox.com/delete/"
(:confirm box)
"\nYou can start a new account any time."
))
(defn send-anxiety [box]
(mailgun-send { :to (:email box)
:subject (bot/ps)
:text (anxiety-text box)}))
;(send-anxiety (data/box-select "ford@ftrain.com"))
================================================
FILE: anxietybox/src/anxietybox/style.clj
================================================
(ns anxietybox.style
(:require
[garden.core :as css]))
(def css
(let [font "'Gentium Basic', serif"
title-font "'Alfa Slab One', cursive"
display-font "'Akronim', cursive"]
(css/css {:pretty-print? false }
[:body
{:margin-left "auto"
:margin-right "auto"
:background "red"
:padding "1em"
:max-width "800px"
:font-family font
:font-size "12pt"
:text-align "center"}]
[:a {:color "inherit"}]
[:h1 :h2
{:font-family title-font
:font-weight "normal"
:margin 0
:padding 0
:color "black"
:text-transform "uppercase"
:font-size "220%"
:line-height "175%"
}]
[:span.sitename
{:font-family display-font
:font-size "300%"
:z-index "-1"
:text-transform "uppercase"
:color "red"
}]
[:b {:color "red"}]
[:h2
{:font-size "130%"
:font-family font
:font-weight "bold"
:margin "1em 5em 1em 5em"
:padding 0
:text-transform "none"
:line-height "129%"
:color "#888"
}]
[:h3 {:margin 0
:padding 0
:font-variant "Italic"
:font-weight "normal"
:color "#88A"
}]
[:div#main
{
:padding "1em"
:border-radius "1em"
:border-left "20px solid #C00"
:border-top "20px solid #D00"
:border-right "20px solid #B00"
:border-bottom "20px solid #A00"
:box-shadow "4px 4px 10px 0px rgba(0, 0, 0, 0.9)"
:background "white"}]
[:div#info
{ :width "50%"
:padding "-1em 0 0 0"
:text-align "left"
:font-size "13pt"
:float "right"
}]
[:div#form
{:color "#666"
:padding "0 1em 0 0"
:margin "0 1em 0 0"
:width "45%"
:text-align "right"
:border-right "1px dotted #ccc"
:font-style "italic"
}]
[:div.gloss
{:padding ".5em 0 1em 0"
:line-height "129%"
:font-size "90%"
}]
[:input.field
{ :font-size "12pt"
:background "#ffe"
:text-align "right"
:clear "both"
:font-family font
:font-weight "bold"
:padding ".25em"
:color "#777"}]
[:input.visited
{ :background "#fff"
:color "#222"
:font-weight "bold"
}]
[:div#footer {:margin-top "20px" :text-align "center" :color "pink"}]
[:div.submit-wrapper
{:width "100%"
:padding-top "1em"
:text-align "center"}
]
[:input.submit
{:margin-left "auto"
:margin-right "auto"
:display "block"
:font-size "25pt"
:border "3px solid red"
:font-family title-font
:background "red"
:color "white"
:border-radius "1em"
:border-left "4px solid #C00"
:border-top "4px solid #D00"
:border-right "4px solid #B00"
:border-bottom "4px solid #A00"
:text-transform "uppercase"
:padding "0 .5em 0 .5em"}]
[:input.submit:hover :input.submit:focus
{:background "#F66"}]
[:input.submit:active
{:background "#F66"
:border-right "4px solid #C00"
:border-bottom "4px solid #D00"
:border-left "4px solid #B00"
:border-top "4px solid #A00"
}]
)))
================================================
FILE: anxietybox/src/resources/templates/activate.mustache
================================================
Dear {{fullname}},
You just signed up for Anxietybox.com. Click here to confirm your email:
http://anxietybox.com/activate/{{confirm}}
If you didn't sign up, ignore this email.
Best wishes,
Your Anxiety
================================================
FILE: anxietybox/src/resources/templates/anxiety.mustache
================================================
Dear {{name}},
I've been thinking a lot about your goal of "{{project}}."
I don't think you'll ever make any progress. It's pretty much
hopeless.
Can you name ONE THING you have ever finished? Think about it. You've
never finished anything, as far as I can tell.
Just prove me wrong by telling me about ONE THING that you completed
and how you did it. No one has every been worse at finishing things
than you have.
Sincerely,
Anxiety
Delete your account: http://anxietybox.com/delete/{{confirm}}
================================================
FILE: anxietybox/src/resources/templates/delete.mustache
================================================
Dear {{fullname}},
Click here to delete your account (you can start a new account any time)
http://localhost:3000/delete/{{confirm}}
================================================
FILE: anxietybox/test/anxietybox/test/handler.clj
================================================
(ns anxietybox.test.handler
(:use clojure.test
ring.mock.request
anxietybox.handler))
(deftest test-app
(testing "main route"
(let [response (app (request :get "/"))]
(is (= (:status response) 200))
(is (= (:body response) "Hello World"))))
(testing "not-found route"
(let [response (app (request :get "/invalid"))]
(is (= (:status response) 404)))))
;; (defn bootstrap []
;; (do (db/box-insert {:fullname "Paul Ford"
;; :email "ford@ftrain.com"
;; :project "The Secret Lives of Web Pages"
;; :confirm (db/uuid)
;; })))
;; (bootstrap)
================================================
FILE: bin/anxiety-piper.pl
================================================
#!/bin/env perl
$email = "";
while () {
die "TOO MANY LINES" if 1000 < $x++;
$email .= $_;
}
$email =~ s/'/\\'/;
$code = "215b7fa466431ae07ac879aad6ba7576";
open (F, "|curl -F'auth=$code&email=$email' --url http://anxietybox.com/reply");
================================================
FILE: schema.sql
================================================
DROP TABLE IF EXISTS account CASCADE;
DROP TABLE IF EXISTS anxiety CASCADE;
DROP TABLE IF EXISTS reply CASCADE;
DROP TABLE IF EXISTS accounts CASCADE;
DROP TABLE IF EXISTS anxieties CASCADE;
DROP TABLE IF EXISTS replies CASCADE;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- The account of a user
CREATE TABLE accounts (
created_time TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(),
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
count INT NOT NULL DEFAULT 0,
confirm uuid DEFAULT UUID_GENERATE_V4(),
active BOOLEAN DEFAULT FALSE
);
CREATE UNIQUE INDEX lower_email_index ON accounts (lower(email));
CREATE UNIQUE INDEX confirm_index ON accounts (confirm);
-- Track anxieties
CREATE TABLE anxieties (
id SERIAL PRIMARY KEY,
account_id int REFERENCES accounts(id) ON DELETE CASCADE,
tracker uuid DEFAULT UUID_GENERATE_V4(),
description text UNIQUE NOT NULL
);
CREATE UNIQUE INDEX track_index ON accounts (confirm);
-- Track replies
CREATE TABLE replies (
created_time TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(),
id SERIAL PRIMARY KEY,
account_id int REFERENCES accounts(id),
anxiety_id int REFERENCES anxieties(id) ON DELETE CASCADE,
description text
);