mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Add admin UI listing all users.
This commit is contained in:
parent
d3655c14db
commit
0157ac3c46
3 changed files with 44 additions and 10 deletions
|
|
@ -56,7 +56,8 @@ func init() {
|
||||||
router.HandleFunc("/account/set-initial-timezone", setInitialTimezoneHandler).Name("set-initial-timezone").Methods("POST")
|
router.HandleFunc("/account/set-initial-timezone", setInitialTimezoneHandler).Name("set-initial-timezone").Methods("POST")
|
||||||
router.HandleFunc("/account/delete", deleteAccountHandler).Name("delete-account").Methods("POST")
|
router.HandleFunc("/account/delete", deleteAccountHandler).Name("delete-account").Methods("POST")
|
||||||
|
|
||||||
router.HandleFunc("/admin/digest", digestAdminHandler)
|
router.HandleFunc("/admin/users", usersAdminHandler)
|
||||||
|
router.HandleFunc("/admin/digest", digestAdminHandler).Name("digest-admin")
|
||||||
http.Handle("/", router)
|
http.Handle("/", router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -608,6 +609,46 @@ func deleteAccountHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
|
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func usersAdminHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
c := appengine.NewContext(r)
|
||||||
|
accounts, err := getAllAccounts(c)
|
||||||
|
if err != nil {
|
||||||
|
c.Errorf("Error looking up accounts: %s", err.Error())
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
users := make([]map[string]interface{}, len(accounts))
|
||||||
|
for i := range accounts {
|
||||||
|
account := &accounts[i]
|
||||||
|
oauthTransport := githubOAuthTransport(c)
|
||||||
|
oauthTransport.Token = &account.OAuthToken
|
||||||
|
githubClient := github.NewClient(oauthTransport.Client())
|
||||||
|
|
||||||
|
user, _, err := githubClient.Users.Get("")
|
||||||
|
|
||||||
|
emailAddress, err := account.GetDigestEmailAddress(githubClient)
|
||||||
|
if err != nil {
|
||||||
|
emailAddress = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
repos, reposErr := getRepos(c, githubClient, account, user)
|
||||||
|
|
||||||
|
users[i] = map[string]interface{}{
|
||||||
|
"Account": account,
|
||||||
|
"User": user,
|
||||||
|
"EmailAddress": emailAddress,
|
||||||
|
"Repos": repos,
|
||||||
|
"ReposError": reposErr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var data = map[string]interface{}{
|
||||||
|
"Users": users,
|
||||||
|
}
|
||||||
|
if err := templates["users-admin"].Execute(w, data); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func digestAdminHandler(w http.ResponseWriter, r *http.Request) {
|
func digestAdminHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
userId, err := strconv.Atoi(r.FormValue("user_id"))
|
userId, err := strconv.Atoi(r.FormValue("user_id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{{define "title"}}Admin{{end}}
|
{{define "title"}}Digest Admin{{end}}
|
||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,7 @@
|
||||||
|
|
||||||
<div class="blurb">
|
<div class="blurb">
|
||||||
You're signed in as
|
You're signed in as
|
||||||
<a href="https://github.com/{{.User.Login}}"
|
{{template "user" .User}}
|
||||||
title="{{.User.Name}}">
|
|
||||||
<img src="{{.User.AvatarURL}}"
|
|
||||||
width="20"
|
|
||||||
height="20"
|
|
||||||
border="0"
|
|
||||||
class="avatar">{{.User.Login}}
|
|
||||||
</a>
|
|
||||||
(<form class="inline" method="POST" action="{{routeUrl "sign-out"}}"><input type="submit" class="inline" value="sign out"></form>).
|
(<form class="inline" method="POST" action="{{routeUrl "sign-out"}}"><input type="submit" class="inline" value="sign out"></form>).
|
||||||
You'll be getting a {{.SettingsSummary.Frequency}} digest of your past
|
You'll be getting a {{.SettingsSummary.Frequency}} digest of your past
|
||||||
GitHub activity in {{.SettingsSummary.RepositoryCount}} repositories sent to
|
GitHub activity in {{.SettingsSummary.RepositoryCount}} repositories sent to
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue