mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Add option to use public repos only.
This commit is contained in:
parent
9a43bfc5bb
commit
c285bc0e02
3 changed files with 36 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ import (
|
||||||
|
|
||||||
var router *mux.Router
|
var router *mux.Router
|
||||||
var githubOauthConfig oauth.Config
|
var githubOauthConfig oauth.Config
|
||||||
|
var githubOauthPublicConfig oauth.Config
|
||||||
var timezones Timezones
|
var timezones Timezones
|
||||||
var sessionStore *sessions.CookieStore
|
var sessionStore *sessions.CookieStore
|
||||||
var sessionConfig SessionConfig
|
var sessionConfig SessionConfig
|
||||||
|
|
@ -36,7 +37,8 @@ func init() {
|
||||||
initTemplates()
|
initTemplates()
|
||||||
timezones = initTimezones()
|
timezones = initTimezones()
|
||||||
sessionStore, sessionConfig = initSession()
|
sessionStore, sessionConfig = initSession()
|
||||||
initGithubOAuthConfig()
|
githubOauthConfig = initGithubOAuthConfig(true)
|
||||||
|
githubOauthPublicConfig = initGithubOAuthConfig(false)
|
||||||
|
|
||||||
router = mux.NewRouter()
|
router = mux.NewRouter()
|
||||||
router.HandleFunc("/", indexHandler).Name("index")
|
router.HandleFunc("/", indexHandler).Name("index")
|
||||||
|
|
@ -58,7 +60,7 @@ func init() {
|
||||||
http.Handle("/", router)
|
http.Handle("/", router)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGithubOAuthConfig() {
|
func initGithubOAuthConfig(includePrivateRepos bool) (config oauth.Config) {
|
||||||
path := "config/github-oauth"
|
path := "config/github-oauth"
|
||||||
if appengine.IsDevAppServer() {
|
if appengine.IsDevAppServer() {
|
||||||
path += "-dev"
|
path += "-dev"
|
||||||
|
|
@ -68,13 +70,18 @@ func initGithubOAuthConfig() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("Could not read GitHub OAuth config from %s: %s", path, err.Error())
|
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 {
|
if err != nil {
|
||||||
log.Panicf("Could not parse GitHub OAuth config %s: %s", configBytes, err.Error())
|
log.Panicf("Could not parse GitHub OAuth config %s: %s", configBytes, err.Error())
|
||||||
}
|
}
|
||||||
githubOauthConfig.Scope = "repo, user:email"
|
repoScopeModifier := ""
|
||||||
githubOauthConfig.AuthURL = "https://github.com/login/oauth/authorize"
|
if !includePrivateRepos {
|
||||||
githubOauthConfig.TokenURL = "https://github.com/login/oauth/access_token"
|
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() {
|
func initTemplates() {
|
||||||
|
|
@ -156,7 +163,11 @@ func loadStyles() (result map[string]template.CSS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func signInHandler(w http.ResponseWriter, r *http.Request) {
|
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) {
|
func signOutHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,19 @@ a {
|
||||||
text-decoration: none;
|
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,
|
||||||
#primary-actions input[type="submit"] {
|
#primary-actions input[type="submit"] {
|
||||||
font-size: 14pt;
|
font-size: 14pt;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
|
|
||||||
<form method="POST" action="{{routeUrl "sign-in"}}">
|
<form id="sign-in-form" method="POST" action="{{routeUrl "sign-in"}}">
|
||||||
<input type="submit" value="Sign In with GitHub">
|
<input type="submit" value="Sign In with GitHub">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="include_private" value="1" checked>
|
||||||
|
Include private repositories
|
||||||
|
</label>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue