Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
arttuka committed Jul 11, 2019
2 parents 5061837 + 64b9d12 commit 699fc67
Show file tree
Hide file tree
Showing 88 changed files with 4,491 additions and 1,871 deletions.
4 changes: 2 additions & 2 deletions mtg-pairings-server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ pom.xml.asc
.classpath
.DS_Store
/resources/public/js
/resources/public/css/main.css
/resources/public/css/main.min.css
/resources/public/css
/resources/manifest.json
30 changes: 20 additions & 10 deletions mtg-pairings-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
FROM openjdk:11-slim AS builder
FROM adoptopenjdk/openjdk12-openj9:alpine AS builder
ENV LEIN_ROOT true
RUN apt-get update && apt-get install -y curl
RUN curl -Lo /usr/bin/lein https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein && chmod +x /usr/bin/lein
RUN apk --no-cache add curl bash \
&& curl -Lo /usr/bin/lein https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \
&& chmod +x /usr/bin/lein
WORKDIR /app
COPY project.clj .
RUN lein deps
COPY ./scripts ./scripts
COPY ./src ./src
COPY ./env ./env
COPY ./dev-resources ./dev-resources
COPY ./resources ./resources
COPY ./test ./test
COPY ./test-resources ./test-resources
COPY prod.cljs.edn .
RUN lein test
RUN lein with-profile provided,prod do clean, garden once, minify-assets, fig:min
RUN ./scripts/tag-assets.sh
RUN lein uberjar
COPY decklist.cljs.edn pairings.cljs.edn ./
RUN lein do \
test, \
kibit, \
eastwood, \
cljfmt check \
&& lein with-profile provided,prod do \
clean, \
garden once, \
minify-assets, \
fig:min pairings, \
fig:min decklist, \
buster, \
uberjar

FROM openjdk:11-jre-slim
FROM adoptopenjdk/openjdk12-openj9:alpine-jre
WORKDIR /app
COPY --from=builder /app/target/mtg-pairings.jar .
CMD ["java", "-jar", "mtg-pairings.jar"]
2 changes: 1 addition & 1 deletion mtg-pairings-server/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -euo pipefail
version=$(git log --pretty=format:'%h' -n 1)
tag=arttuka/pairings:$version

docker build . -t $tag --network mtgsuomi-deployment_default
docker build . -t $tag --network mtgsuomi-deployment_default --pull
docker tag $tag arttuka/pairings:latest
4 changes: 4 additions & 0 deletions mtg-pairings-server/decklist.cljs.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:main mtg-pairings-server.decklist
:output-to "target/public/js/decklist-main.js"
:output-dir "target/public/js/compiled/decklist"
:optimizations :advanced}
1 change: 1 addition & 0 deletions mtg-pairings-server/dev-resources/public/css/slider.css
2 changes: 1 addition & 1 deletion mtg-pairings-server/dev.cljs.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
^{:watch-dirs ["src/cljs" "src/cljc" "env/dev/cljs"]
:css-dirs ["resources/public/css"]
:css-dirs ["dev-resources/public/css" "target/public/css"]
:open-url false}
{:main mtg-pairings-server.dev
:preloads [re-frisk.preload]
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions mtg-pairings-server/pairings.cljs.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:main mtg-pairings-server.pairings
:output-to "target/public/js/pairings-main.js"
:output-dir "target/public/js/compiled/pairings"
:optimizations :advanced}
5 changes: 0 additions & 5 deletions mtg-pairings-server/prod.cljs.edn

This file was deleted.

66 changes: 41 additions & 25 deletions mtg-pairings-server/project.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(defproject mtg-pairings-server "2.2.1"
:license {:name "MIT License"
:url "http://www.opensource.org/licenses/mit-license.php"}
:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/core.async "0.4.490"]
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/core.async "0.4.500"]
[org.clojure/tools.logging "0.4.1"]
[ring/ring-core "1.7.1"]
[ring/ring-defaults "0.3.2"]
[hiccup "1.0.5"]
[yogthos/config "1.1.1"]
[yogthos/config "1.1.4"]
[org.clojure/core.cache "0.7.2"]
[aleph "0.4.6"]
[clj-time "0.15.1"]
[korma "0.4.3" :exclusions [com.mchange/c3p0]]
[mount "0.1.16"]
[org.postgresql/postgresql "42.2.5"]
[org.postgresql/postgresql "42.2.6"]
[hikari-cp "2.7.1"]
[metosin/compojure-api "1.1.12"]
[org.flatland/ordered "1.5.7"]
Expand All @@ -22,15 +22,22 @@
[com.taoensso/sente "1.14.0-RC2"]
[com.taoensso/timbre "4.10.0"]
[com.cognitect/transit-clj "0.8.313"]
[com.fzakaria/slf4j-timbre "0.3.12"]]
:plugins [[lein-asset-minifier "0.4.6"]
[com.fzakaria/slf4j-timbre "0.3.13"]
[garden "1.3.9"]]
:plugins [[lein-ancient "0.6.15"]
[lein-asset-minifier "0.4.6"]
[lein-cljfmt "0.6.4"]
[lein-ancient "0.6.15"]
[lein-garden "0.3.0" :exclusions [org.apache.commons/commons-compress]]]
[lein-garden "0.3.0" :exclusions [org.apache.commons/commons-compress]]
[lein-kibit "0.1.6"]
[jonase/eastwood "0.3.6"]
[no.terjedahl/lein-buster "0.2.0"]]

:uberjar-name "mtg-pairings.jar"

:clean-targets ^{:protect false} ["target"]
:clean-targets ^{:protect false} ["target"
"resources/public/js"
"resources/public/css"
"resources/manifest.json"]

:source-paths ["src/clj" "src/cljc" "src/cljs"]
:resource-paths ["resources"]
Expand All @@ -43,11 +50,18 @@
:pretty-print? true}}]}

:minify-assets [[:css {:source ["target/public/css/main.css"
"resources/public/css/slider.css"]
"resources/private/slider.css"]
:target "target/public/css/main.min.css"}]]

:buster {:files ["target/public/js/pairings-main.js"
"target/public/js/decklist-main.js"
"target/public/css/main.min.css"]
:files-base "target/public"
:output-base "resources/public"
:manifest "resources/manifest.json"}

:aliases {"fig" ["trampoline" "run" "-m" "figwheel.main"]
"fig:min" ["run" "-m" "figwheel.main" "-bo" "prod"]}
"fig:min" ["run" "-m" "figwheel.main" "-bo"]}

:cljfmt {:indents {reg-sub [[:inner 0]]
reg-fx [[:inner 0]]
Expand All @@ -69,19 +83,22 @@
sql-util/update-unique [[:inner 0]]
validate-request [[:inner 0]]}}

:eastwood {:namespaces [:source-paths :test-paths]
:config-files ["test-resources/eastwood.clj"]}

:profiles {:dev {:repl-options {:init-ns mtg-pairings-server.repl
:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}
:source-paths ["dev" "env/dev/clj" "env/dev/cljs"]
:resource-paths ["target"]
:resource-paths ["dev-resources" "target"]
:test-paths ["test/clj"]
:dependencies [[org.clojure/tools.namespace "0.2.11"]
:dependencies [[org.clojure/tools.namespace "0.3.0"]
[binaryage/devtools "0.9.10"]
[com.bhauman/rebel-readline-cljs "0.1.4" :exclusions [org.clojure/clojurescript]]
[ring/ring-mock "0.3.2"]
[ring/ring-mock "0.4.0"]
[ring/ring-devel "1.7.1"]
[prone "1.6.1"]
[prone "1.6.4"]
[hawk "0.2.11"]
[cider/piggieback "0.4.0" :exclusions [org.clojure/clojurescript]]
[cider/piggieback "0.4.1" :exclusions [org.clojure/clojurescript]]
[re-frisk "0.5.4.1" :exclusions [org.clojure/clojurescript]]]}
:test {:source-paths ^:replace ["src/clj" "src/cljc" "src/cljs"]
:resource-paths ["test-resources"]}
Expand All @@ -90,22 +107,21 @@
[reagent "0.8.1"]
[com.google.errorprone/error_prone_annotations "2.3.3"]
[com.google.code.findbugs/jsr305 "3.0.2"]
[com.bhauman/figwheel-main "0.2.0" :exclusions [org.clojure/clojurescript]]
[com.bhauman/figwheel-main "0.2.1" :exclusions [org.clojure/clojurescript]]
[clj-commons/secretary "1.2.4"]
[venantius/accountant "0.2.4"]
[com.cognitect/transit-cljs "0.8.256"]
[com.andrewmcveigh/cljs-time "0.5.2"]
[re-frame "0.10.6" :exclusions [cljsjs/react org.clojure/clojurescript]]
[re-frame "0.10.7" :exclusions [cljsjs/react org.clojure/clojurescript]]
[binaryage/oops "0.7.0"]
[cljsjs/react "16.8.3-0"]
[cljsjs/react-dom "16.8.3-0"]
[cljsjs/react-dom-server "16.8.3-0"]
[cljsjs/react "16.8.6-0"]
[cljsjs/react-dom "16.8.6-0"]
[cljsjs/react-dom-server "16.8.6-0"]
[cljs-react-material-ui "0.2.50" :exclusions [org.clojure/clojurescript]]
[cljsjs/prop-types "15.6.2-0"]
[cljsjs/rc-slider "8.6.1-0"]
[garden "1.3.6"]]}
[cljsjs/react-autosuggest "9.4.3-0"]]}
:uberjar {:source-paths ["env/prod/cljs"]
:main mtg-pairings-server.main
:aot :all
:uberjar-exclusions [#"public/css/slider.css"]
:omit-source true}})
:omit-source true
:auto-clean false}})
29 changes: 29 additions & 0 deletions mtg-pairings-server/resources/private/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,33 @@ create table pod_seat (
seat int not null
);

create table decklist_tournament (
id char(22) not null primary key,
"user" integer not null references smf_members(id_member),
name text not null,
date date not null,
deadline timestamptz,
format text not null
);

create table decklist (
id char(22) not null primary key,
tournament char(22) not null references decklist_tournament(id),
submitted timestamptz not null,
name text,
"last-name" text,
"first-name" text,
dci text,
email text
);

create table decklist_card (
decklist char(22) not null references decklist(id),
maindeck boolean not null,
card int not null references trader_card(id),
index int not null,
quantity int not null,
primary key (decklist, maindeck, card)
);

commit;
18 changes: 0 additions & 18 deletions mtg-pairings-server/scripts/tag-assets.sh

This file was deleted.

13 changes: 6 additions & 7 deletions mtg-pairings-server/src/clj/mtg_pairings_server/api/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
{:ui "/api-docs"
:spec "/swagger.json"
:data {:info {:title "WER pairings backend API"}}})
(context "/api" []
(context "/tournament" [] tournament-routes)
(context "/player" [] player-routes)
(GET "/client-version" []
:no-doc true
{:status 200
:body {:version (env :client-version)}})))
(context "/tournament" [] tournament-routes)
(context "/player" [] player-routes)
(GET "/client-version" []
:no-doc true
{:status 200
:body {:version (env :client-version)}}))
46 changes: 46 additions & 0 deletions mtg-pairings-server/src/clj/mtg_pairings_server/auth.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(ns mtg-pairings-server.auth
(:require [clojure.string :as str]
[compojure.api.sweet :refer :all]
[config.core :refer [env]]
[ring.util.response :refer [redirect]]
[schema.core :as s]
[korma.core :as sql]
[mtg-pairings-server.sql-db :as db]
[mtg-pairings-server.util.sql :as sql-util])
(:import (java.security MessageDigest)))

(defn ^:private ->hex [bytes]
(str/join (for [b bytes] (format "%02x" b))))

(defn ^:private authenticate [username password]
(when-let [user (sql-util/select-unique-or-nil db/smf-user
(sql/fields [:id_member :id] [:passwd :hash])
(sql/where {:member_name username}))]
(let [input (str (str/lower-case username) password)
md (doto (MessageDigest/getInstance "SHA-1")
(.update (.getBytes input "UTF-8")))
sha1 (->hex (.digest md))]
(when (= sha1 (:hash user))
{:id (:id user)
:username username}))))

(defn organizer-path []
(if (str/blank? (env :decklist-prefix))
"/decklist/organizer"
"/organizer"))

(defroutes auth-routes
(POST "/login" request
:form-params [username :- s/Str
password :- s/Str
__anti-forgery-token :- s/Str]
:query-params [next :- s/Str]
(if-let [user (authenticate username password)]
(let [new-session (assoc (:session request) :identity user)]
(assoc (redirect next :see-other)
:session new-session))
(redirect (organizer-path) :see-other)))
(GET "/logout" request
(let [new-session (dissoc (:session request) :identity)]
(assoc (redirect (organizer-path) :see-other)
:session new-session))))
Loading

0 comments on commit 699fc67

Please sign in to comment.