implementing permissions to companies
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
<title>Auto AP</title>
|
<title>Auto AP</title>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
|
||||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
|
||||||
<script src="https://cdn.auth0.com/js/lock/10.24/lock.min.js"></script>
|
|
||||||
<!-- Bulma Version 0.6.0 -->
|
<!-- Bulma Version 0.6.0 -->
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css" integrity="sha256-HEtF7HLJZSC3Le1HcsWbz1hDYFPZCqDhZa9QsCgVUdw=" crossorigin="anonymous" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css" integrity="sha256-HEtF7HLJZSC3Le1HcsWbz1hDYFPZCqDhZa9QsCgVUdw=" crossorigin="anonymous" />
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[auto-ap.db.invoices :as invoices]
|
[auto-ap.db.invoices :as invoices]
|
||||||
|
[auto-ap.db.users :as users]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.parse :as parse]
|
||||||
[ring.middleware.multipart-params :as mp]
|
[ring.middleware.multipart-params :as mp]
|
||||||
[ring.util.response :as response]
|
[ring.util.response :as response]
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
(response/resource-response "index.html" {:root "public"}))
|
(response/resource-response "index.html" {:root "public"}))
|
||||||
(GET "/api/oauth" {{:strs [code]} :query-params}
|
(GET "/api/oauth" {{:strs [code]} :query-params}
|
||||||
(try
|
(try
|
||||||
(let [token (-> "https://accounts.google.com/o/oauth2/token"
|
(let [auth (-> "https://accounts.google.com/o/oauth2/token"
|
||||||
(http/post
|
(http/post
|
||||||
{:form-params {"client_id" google-client-id
|
{:form-params {"client_id" google-client-id
|
||||||
"client_secret" google-client-secret
|
"client_secret" google-client-secret
|
||||||
@@ -50,18 +51,22 @@
|
|||||||
"redirect_uri" "http://localhost:3449/api/oauth"
|
"redirect_uri" "http://localhost:3449/api/oauth"
|
||||||
"grant_type" "authorization_code"}
|
"grant_type" "authorization_code"}
|
||||||
:as :json})
|
:as :json})
|
||||||
:body
|
:body)
|
||||||
:access_token)
|
token (:access_token auth)
|
||||||
profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo"
|
profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo"
|
||||||
{:headers {"Authorization" (str "Bearer " token)} :as :json})
|
{:headers {"Authorization" (str "Bearer " token)} :as :json})
|
||||||
:body
|
:body
|
||||||
:name)
|
(doto println)
|
||||||
]
|
)
|
||||||
(if token
|
user (users/find-or-insert! {:provider "google"
|
||||||
|
:provider_id (:id profile)})]
|
||||||
|
|
||||||
|
(if (and token user)
|
||||||
{:status 301
|
{:status 301
|
||||||
:headers {"Location" (str "/?jwt=" (jwt/sign {:user "test"
|
:headers {"Location" (str "/?jwt=" (jwt/sign {:user "test"
|
||||||
:exp (time/plus (time/now) (time/days 7))
|
:exp (time/plus (time/now) (time/days 7))
|
||||||
:name profile}
|
:companies (:companies user)
|
||||||
|
:name (:name profile)}
|
||||||
jwt-secret
|
jwt-secret
|
||||||
{:alg :hs512}))}}
|
{:alg :hs512}))}}
|
||||||
{:status 401
|
{:status 401
|
||||||
|
|||||||
@@ -3,12 +3,7 @@
|
|||||||
(def default-db
|
(def default-db
|
||||||
{:user (.getItem js/localStorage "jwt")
|
{:user (.getItem js/localStorage "jwt")
|
||||||
:company {:name "Campbell Brewing Company"}
|
:company {:name "Campbell Brewing Company"}
|
||||||
:companies [{:name "Campbell Brewing Company"
|
:companies []
|
||||||
:matches ["campbell brewing company" "campbell brewery company" "campbell brewing"]}
|
|
||||||
{:name "Brown Chicken Brown Cow"
|
|
||||||
:matches ["brown chicken brown cow"]}
|
|
||||||
{:name "Naschmarkt Restaurant"
|
|
||||||
:matches ["naschmarkt" "naschmarkt restaurant"]}]
|
|
||||||
:invoices {:pending #{}
|
:invoices {:pending #{}
|
||||||
:unpaid #{}}
|
:unpaid #{}}
|
||||||
:status {:loading false}
|
:status {:loading false}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::companies
|
::companies
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:companies db)))
|
(when (:user db)
|
||||||
|
(let [{:strs [companies] :as x} (js->clj (.parse js/JSON (base64/decodeString (second (str/split (:user db) #"\.")))))]
|
||||||
|
(map (fn [c] {:name c}) companies)))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::menu
|
::menu
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
(ns auto-ap.handler-test
|
|
||||||
(:require [clojure.test :refer :all]
|
|
||||||
[ring.mock.request :as mock]
|
|
||||||
[auto-ap.handler :refer :all]))
|
|
||||||
|
|
||||||
(deftest test-app
|
|
||||||
(testing "main route"
|
|
||||||
(let [response (app (mock/request :get "/"))]
|
|
||||||
(is (= (:status response) 200))
|
|
||||||
(is (= (:body response) "Hello World"))))
|
|
||||||
|
|
||||||
(testing "not-found route"
|
|
||||||
(let [response (app (mock/request :get "/invalid"))]
|
|
||||||
(is (= (:status response) 404)))))
|
|
||||||
Reference in New Issue
Block a user