Verified Commit c07fbd53 authored by Kamalavelan's avatar Kamalavelan 💬

Update homepage, work on user auth, registration

Signed-off-by: Kamalavelan's avatarKamalavelan <sskamalavelan@gmail.com>
parent cbc48692
{
"name": "thiral",
"version": "1.0.0",
"description": "*thiral* is an experiment in radical transparency & coordinated action for communities rallying around social action",
"main": "index.js",
"directories": {
"test": "test"
},
"dependencies": {
"leaflet": "^1.4.0",
"shadow-cljs": "^2.8.21"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/demonshreder/thiral.git"
},
"author": "Kamalavelan",
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://gitlab.com/demonshreder/thiral/issues"
},
"homepage": "https://gitlab.com/demonshreder/thiral#readme"
}
......@@ -2,7 +2,7 @@
(:require [io.pedestal.http :as http]
[io.pedestal.http.route :as route]
[io.pedestal.http.body-params :as body-params]
[io.pedestal.http.ring-middlewares :as middlewares]
[io.pedestal.http.ring-middlewares :as middlewares]
[io.pedestal.interceptor :as interceptor]
[io.pedestal.interceptor.chain :as interceptor.chain]
[io.pedestal.interceptor.error :refer [error-dispatch]]
......@@ -14,9 +14,7 @@
[buddy.auth.backends :as auth.backends]
[buddy.auth.middleware :as auth.middleware]
;; [mount.core :refer defstate]
))
))
(def secret (:secret (clojure.edn/read-string (slurp "resources/env/secret.edn"))))
......@@ -55,24 +53,24 @@
(assoc ctx
:response
(auth.middleware/authorization-error (:request ctx)
ex
ex
backend))
(catch Exception e
(assoc ctx ::interceptor.chain/error e)))
:else (assoc ctx ::interceptor.chain/error ex)))
(def common-interceptors [
(body-params/body-params)
(def common-interceptors [(body-params/body-params)
http/html-body
authentication-interceptor
(authorization-interceptor backend)
])
(authorization-interceptor backend)])
;; Tabular routes
(def routes #{["/" :get (conj common-interceptors `home/home-page)]
["/about" :get (conj common-interceptors `about-page)]
["/login" :get (conj common-interceptors `site.auth/login)]})
["/login" :get (conj common-interceptors `site.auth/login-post)]})
;; Map-based routes
;(def routes `{"/" {:interceptors [(body-params/body-params) http/html-body]
......@@ -95,7 +93,7 @@
;; default interceptors will be ignored.
;; ::http/interceptors []
::http/routes routes
;; Uncomment next line to enable CORS support, add
;; string(s) specifying scheme, host and port for
;; allowed source(s):
......
......@@ -3,25 +3,24 @@
(:use
[hiccup.page :only (html5 include-css include-js)]))
(defn base [title & content]
(defn base [title headers & content]
(html5 {:lang "en"}
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1"}]
[:link {:rel "icon" :type "image/png" :href "/img/FSHM_logo.png"}]
;; [:link {:rel "icon" :type "image/png" :href "/img/favico.png"}]
[:title title]
(include-css "/css/bulma.min.css")
(include-js "/js/main.js")]
(include-css "/css/bulma.min.css" "https://cdn.jsdelivr.net/npm/fork-awesome@1.1.7/css/fork-awesome.min.css")
(vals headers)]
[:body
[:nav.navbar
{:aria-label "main navigation", :role "navigation"}
[:div.navbar-brand
[:a.navbar-item
{:href "/"}
[:img
{:height "100",
:width "100",
:src "/img/FSHM_logo.png"}]]
;; [:i.fa.fa-activitypub.fa-3x]]
[:img {:src "/img/logo.png"}]]
[:a.navbar-burger.burger
{:data-target "navbarBasicExample",
:aria-expanded "false",
......
(ns thiral.site.auth
(:require [hiccup.core :as hiccup]
(:require [buddy.hashers :as hashers]
[hiccup.core :as hiccup]
[ring.util.response :as ring-resp]
[thiral.site :as site]))
[thiral.site :as site]
[thiral.db.users :as users]))
;; https://juxt.pro/blog/posts/securing-your-clojurescript-app.html
(defn authenticate [data]
"Authenticates user credentials from db"
(let [datum (users/users-by-email (:email data))]))
(defn login-page [request]
(ring-resp/response (site/base
"home"
[:h1 "hello"]
)))
(defn new-user [data]
"Creates a new user in the db"
(println data)
(let [datum
{:email (:email data)
:password (hashers/derive (:password data) {:alg :bcrypt+blake2b-512})}]
(println datum)
(users/users-create datum)))
;; https://juxt.pro/blog/posts/securing-your-clojurescript-app.html
(defn login [request]
(-> (ring-resp/redirect "/")
(assoc :session {:token "token"})))
(defn login-post [request]
(-> (ring-resp/redirect "/")
(assoc :session {:token "token"})))
(defn register-post [request]
(-> (ring-resp/redirect "/")
(assoc :session {:token "token"})))
(defn register-page [request]
(defn auth-page [request]
(ring-resp/response (site/base
"home"
[:h1 "hello"]
)))
"Login or Register"
[:h1 "hello"])))
(defn auth-control []
(hiccup/html
[:div.field
[:label.label "Email"]
[:div.control
[:input.input {:type "email" :placeholder "yourname@mail.com"}]]]
[:div.field
[:label.label "Password"]
[:div.control
[:input.input {:type "password" :placeholder "yourname@mail.com"}]]]))
(ns thiral.site.home
(:require [hiccup.core :as hiccup]
[hiccup.page :only (include-js)]
[ring.util.response :as ring-resp]
[thiral.site :as site]))
(defn home-page [request]
(-> (ring-resp/response (site/base
"FSHM"
[:h1 "hello"]))
(assoc :session {:sexy "cool"}
"Thiral"
{:a [:link
{:crossorigin "",
:href "https://unpkg.com/leaflet@1.4.0/dist/leaflet.css",
:rel "stylesheet"}]
:b [:script {:src "https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"}]}
;;[:div#mapid {:style "height: 400px;"}]
[:h1 "hello"]
[:div.column.is-one-fifth.is-offset-three-quarters (thiral.site.auth/auth-control)]
;;[:script {:src "/js/main-script.js"}]
))
;;(assoc :session {:sexy "cool"}
;;:status 401
:cookies {:bird "kek"})))
;; :cookies {:bird "kek"})
))
......@@ -8,9 +8,9 @@
(::bootstrap/service-fn (bootstrap/create-servlet service/service)))
(deftest home-page-test
(is (=
(:body (response-for service :get "/"))
"Hello World!"))
;; (is (=
;; (:body (response-for service :get "/"))
;; "Hello World!"))
(is (=
(:headers (response-for service :get "/"))
{"Content-Type" "text/html;charset=UTF-8"
......@@ -23,9 +23,9 @@
"Content-Security-Policy" "object-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;"})))
(deftest about-page-test
(is (.contains
(:body (response-for service :get "/about"))
"Clojure 1.9"))
;;(is (.contains
;; (:body (response-for service :get "/about"))
;; "Clojure 1.9"))
(is (=
(:headers (response-for service :get "/about"))
{"Content-Type" "text/html;charset=UTF-8"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment