Fix saving of users' email
Previously the user's email did not get saved to the db unless it was defined as public in the profile. This commit adds an additional oauth scope for accessing the user's emails, and the user's primary email address is saved to the db.
This commit is contained in:
parent
480d85f6b5
commit
b3909f4e60
|
@ -26,7 +26,7 @@
|
||||||
(defn authorize-url []
|
(defn authorize-url []
|
||||||
(let [params (codec/form-encode {:client_id (client-id)
|
(let [params (codec/form-encode {:client_id (client-id)
|
||||||
:redirect_uri (redirect-uri)
|
:redirect_uri (redirect-uri)
|
||||||
:scope "admin:repo_hook repo admin:org_hook"
|
:scope "admin:repo_hook user:email repo admin:org_hook"
|
||||||
:allow_signup true
|
:allow_signup true
|
||||||
:state (str (UUID/randomUUID))})]
|
:state (str (UUID/randomUUID))})]
|
||||||
(str "https://github.com/login/oauth/authorize" "?" params)))
|
(str "https://github.com/login/oauth/authorize" "?" params)))
|
||||||
|
@ -82,6 +82,14 @@
|
||||||
[token]
|
[token]
|
||||||
(users/me (auth-params token)))
|
(users/me (auth-params token)))
|
||||||
|
|
||||||
|
(defn get-user-email
|
||||||
|
[token]
|
||||||
|
(let [emails (users/emails (auth-params token))]
|
||||||
|
(->
|
||||||
|
(filter :primary emails)
|
||||||
|
first
|
||||||
|
:email)))
|
||||||
|
|
||||||
(defn add-webhook
|
(defn add-webhook
|
||||||
[full-repo token]
|
[full-repo token]
|
||||||
(log/debug "adding webhook" full-repo token)
|
(log/debug "adding webhook" full-repo token)
|
||||||
|
|
|
@ -24,20 +24,28 @@
|
||||||
(defn generate-image
|
(defn generate-image
|
||||||
[address balance issue-url width height]
|
[address balance issue-url width height]
|
||||||
(let [qr-code-image (ImageIO/read (generate-qr-code address))
|
(let [qr-code-image (ImageIO/read (generate-qr-code address))
|
||||||
comment-image (html->image (generate-html address balance issue-url) width height)]
|
comment-image (html->image
|
||||||
|
(generate-html address balance issue-url) width height)]
|
||||||
(combine-images qr-code-image comment-image)))
|
(combine-images qr-code-image comment-image)))
|
||||||
|
|
||||||
(defapi qr-routes
|
(defapi qr-routes
|
||||||
(context "/qr" []
|
(context "/qr" []
|
||||||
|
;; user may be an organization here
|
||||||
(GET "/:user/:repo/bounty/:issue{[0-9]{1,9}}/:hash/qr.png" [user repo issue hash]
|
(GET "/:user/:repo/bounty/:issue{[0-9]{1,9}}/:hash/qr.png" [user repo issue hash]
|
||||||
(if (= hash (github/github-comment-hash user repo issue))
|
(log/debug "qr PNG GET")
|
||||||
(let [{address :contract_address
|
(let [{address :contract_address
|
||||||
login :login
|
login :login
|
||||||
repo :repo
|
repo :repo
|
||||||
issue-number :issue_number} (bounties/get-bounty-address user repo (Integer/parseInt issue))]
|
issue-number :issue_number}
|
||||||
(if address
|
(bounties/get-bounty-address user
|
||||||
(let [balance (eth/get-balance-eth address 8)
|
repo
|
||||||
issue-url (str login "/" repo "/issues/" issue-number)]
|
(Integer/parseInt issue))
|
||||||
|
balance (eth/get-balance-eth address 8)]
|
||||||
|
(log/debug "address:" address "balance:" balance)
|
||||||
|
|
||||||
|
(if (and address
|
||||||
|
(= hash (github/github-comment-hash user repo issue balance)))
|
||||||
|
(let [issue-url (str login "/" repo "/issues/" issue-number)]
|
||||||
|
(log/debug "balance:" address)
|
||||||
(ok (generate-image address balance issue-url 768 256)))
|
(ok (generate-image address balance issue-url 768 256)))
|
||||||
(bad-request)))
|
(bad-request))))))
|
||||||
(bad-request)))))
|
|
||||||
|
|
|
@ -8,18 +8,27 @@
|
||||||
[ring.util.http-response :refer [content-type ok]]
|
[ring.util.http-response :refer [content-type ok]]
|
||||||
[ring.util.response :as response]
|
[ring.util.response :as response]
|
||||||
[commiteth.layout :refer [render]]
|
[commiteth.layout :refer [render]]
|
||||||
[cheshire.core :refer [generate-string]]))
|
[cheshire.core :refer [generate-string]]
|
||||||
|
[clojure.tools.logging :as log]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defn- create-user [token user]
|
||||||
|
(let [{name :name
|
||||||
|
login :login
|
||||||
|
user-id :id} user
|
||||||
|
email (github/get-user-email token)]
|
||||||
|
(users/create-user user-id login name email token)))
|
||||||
|
|
||||||
(defn- get-or-create-user
|
(defn- get-or-create-user
|
||||||
[token]
|
[token]
|
||||||
(let [user (github/get-user token)
|
(let [user (github/get-user token)
|
||||||
{email :email
|
{email :email
|
||||||
name :name
|
|
||||||
login :login
|
|
||||||
user-id :id} user]
|
user-id :id} user]
|
||||||
|
(log/debug "get-or-create-user" user)
|
||||||
(or
|
(or
|
||||||
(users/update-user-token user-id token)
|
(users/update-user-token user-id token)
|
||||||
(users/create-user user-id login name email token))))
|
(create-user token user))))
|
||||||
|
|
||||||
(defroutes redirect-routes
|
(defroutes redirect-routes
|
||||||
(GET "/callback" [code state]
|
(GET "/callback" [code state]
|
||||||
|
|
Loading…
Reference in New Issue