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 []
|
||||
(let [params (codec/form-encode {:client_id (client-id)
|
||||
: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
|
||||
:state (str (UUID/randomUUID))})]
|
||||
(str "https://github.com/login/oauth/authorize" "?" params)))
|
||||
|
@ -82,6 +82,14 @@
|
|||
[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
|
||||
[full-repo token]
|
||||
(log/debug "adding webhook" full-repo token)
|
||||
|
|
|
@ -24,20 +24,28 @@
|
|||
(defn generate-image
|
||||
[address balance issue-url width height]
|
||||
(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)))
|
||||
|
||||
(defapi qr-routes
|
||||
(context "/qr" []
|
||||
(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))
|
||||
(let [{address :contract_address
|
||||
login :login
|
||||
repo :repo
|
||||
issue-number :issue_number} (bounties/get-bounty-address user repo (Integer/parseInt issue))]
|
||||
(if address
|
||||
(let [balance (eth/get-balance-eth address 8)
|
||||
issue-url (str login "/" repo "/issues/" issue-number)]
|
||||
(ok (generate-image address balance issue-url 768 256)))
|
||||
(bad-request)))
|
||||
(bad-request)))))
|
||||
;; user may be an organization here
|
||||
(GET "/:user/:repo/bounty/:issue{[0-9]{1,9}}/:hash/qr.png" [user repo issue hash]
|
||||
(log/debug "qr PNG GET")
|
||||
(let [{address :contract_address
|
||||
login :login
|
||||
repo :repo
|
||||
issue-number :issue_number}
|
||||
(bounties/get-bounty-address user
|
||||
repo
|
||||
(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)))
|
||||
(bad-request))))))
|
||||
|
|
|
@ -8,18 +8,27 @@
|
|||
[ring.util.http-response :refer [content-type ok]]
|
||||
[ring.util.response :as response]
|
||||
[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
|
||||
[token]
|
||||
(let [user (github/get-user token)
|
||||
{email :email
|
||||
name :name
|
||||
login :login
|
||||
user-id :id} user]
|
||||
(log/debug "get-or-create-user" user)
|
||||
(or
|
||||
(users/update-user-token user-id token)
|
||||
(users/create-user user-id login name email token))))
|
||||
(create-user token user))))
|
||||
|
||||
(defroutes redirect-routes
|
||||
(GET "/callback" [code state]
|
||||
|
|
Loading…
Reference in New Issue