From c285bc0e022526c7d55f5bb876c1a9fe4de55516 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Fri, 17 Oct 2014 21:06:55 -0700 Subject: [PATCH] Add option to use public repos only. --- app/githop.go | 25 ++++++++++++++++++------- app/static/main.css | 13 +++++++++++++ app/templates/index-signed-out.html | 6 +++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/app/githop.go b/app/githop.go index 6202212..7bea95a 100644 --- a/app/githop.go +++ b/app/githop.go @@ -27,6 +27,7 @@ import ( var router *mux.Router var githubOauthConfig oauth.Config +var githubOauthPublicConfig oauth.Config var timezones Timezones var sessionStore *sessions.CookieStore var sessionConfig SessionConfig @@ -36,7 +37,8 @@ func init() { initTemplates() timezones = initTimezones() sessionStore, sessionConfig = initSession() - initGithubOAuthConfig() + githubOauthConfig = initGithubOAuthConfig(true) + githubOauthPublicConfig = initGithubOAuthConfig(false) router = mux.NewRouter() router.HandleFunc("/", indexHandler).Name("index") @@ -58,7 +60,7 @@ func init() { http.Handle("/", router) } -func initGithubOAuthConfig() { +func initGithubOAuthConfig(includePrivateRepos bool) (config oauth.Config) { path := "config/github-oauth" if appengine.IsDevAppServer() { path += "-dev" @@ -68,13 +70,18 @@ func initGithubOAuthConfig() { if err != nil { log.Panicf("Could not read GitHub OAuth config from %s: %s", path, err.Error()) } - err = json.Unmarshal(configBytes, &githubOauthConfig) + err = json.Unmarshal(configBytes, &config) if err != nil { log.Panicf("Could not parse GitHub OAuth config %s: %s", configBytes, err.Error()) } - githubOauthConfig.Scope = "repo, user:email" - githubOauthConfig.AuthURL = "https://github.com/login/oauth/authorize" - githubOauthConfig.TokenURL = "https://github.com/login/oauth/access_token" + repoScopeModifier := "" + if !includePrivateRepos { + repoScopeModifier = "public_" + } + config.Scope = fmt.Sprintf("%srepo user:email", repoScopeModifier) + config.AuthURL = "https://github.com/login/oauth/authorize" + config.TokenURL = "https://github.com/login/oauth/access_token" + return } func initTemplates() { @@ -156,7 +163,11 @@ func loadStyles() (result map[string]template.CSS) { } func signInHandler(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, githubOauthConfig.AuthCodeURL(""), http.StatusFound) + config := &githubOauthConfig + if r.FormValue("include_private") != "1" { + config = &githubOauthPublicConfig + } + http.Redirect(w, r, config.AuthCodeURL(""), http.StatusFound) } func signOutHandler(w http.ResponseWriter, r *http.Request) { diff --git a/app/static/main.css b/app/static/main.css index 167e5ab..3c3313d 100644 --- a/app/static/main.css +++ b/app/static/main.css @@ -8,6 +8,19 @@ a { text-decoration: none; } +#sign-in-form { + margin: 0 auto; +} + +#sign-in-form input[type="submit"] { + font-size: 18pt; + font-weight: bold; +} + +#sign-in-form label { + display: block; +} + #primary-actions, #primary-actions input[type="submit"] { font-size: 14pt; diff --git a/app/templates/index-signed-out.html b/app/templates/index-signed-out.html index c067897..ddea907 100644 --- a/app/templates/index-signed-out.html +++ b/app/templates/index-signed-out.html @@ -2,8 +2,12 @@ {{define "body"}} -
+ +
{{end}}