Add admin command for deleting accounts.

This commit is contained in:
Mihai Parparita 2014-12-27 21:17:52 -08:00
parent 00e19e79b4
commit 3d5bf2cad4
2 changed files with 27 additions and 1 deletions

View file

@ -56,8 +56,9 @@ func init() {
router.Handle("/account/set-initial-timezone", SignedInAppHandler(setInitialTimezoneHandler)).Name("set-initial-timezone").Methods("POST")
router.Handle("/account/delete", SignedInAppHandler(deleteAccountHandler)).Name("delete-account").Methods("POST")
router.Handle("/admin/users", AppHandler(usersAdminHandler))
router.Handle("/admin/users", AppHandler(usersAdminHandler)).Name("users-admin")
router.Handle("/admin/digest", AppHandler(digestAdminHandler)).Name("digest-admin")
router.Handle("/admin/delete-account", AppHandler(deleteAccountAdminHandler)).Name("delete-account-admin")
http.Handle("/", router)
}
@ -624,6 +625,24 @@ func digestAdminHandler(w http.ResponseWriter, r *http.Request) *AppError {
return templates["digest-admin"].Render(w, data)
}
func deleteAccountAdminHandler(w http.ResponseWriter, r *http.Request) *AppError {
userId, err := strconv.Atoi(r.FormValue("user_id"))
if err != nil {
return BadRequest(err, "Malformed user_id value")
}
c := appengine.NewContext(r)
account, err := getAccount(c, userId)
if account == nil {
return BadRequest(err, "user_id does not point to an account")
}
if err != nil {
return InternalError(err, "Could not look up account")
}
account.Delete(c)
return RedirectToRoute("users-admin")
}
func githubOAuthTransport(c appengine.Context) *oauth.Transport {
appengineTransport := &urlfetch.Transport{Context: c}
appengineTransport.Deadline = time.Second * 60

View file

@ -16,6 +16,7 @@
<th>Email</th>
<th>Frequency</th>
<th>Repositories</th>
<th>Account</th>
</tr>
</thead>
<tbody>
@ -38,6 +39,12 @@
{{len .Repos.AllRepos}} from {{len .Repos.OtherUserRepos}} other users and {{len .Repos.OrgRepos}} organizations
{{end}}
</td>
<td>
<form method="POST" action="{{routeUrl "delete-account-admin"}}" onsubmit="return confirm('Really delete?')">
<input type="hidden" name="user_id" value="{{.Account.GitHubUserId}}">
<input type="submit" value="Delete">
</form>
</td>
</tr>
{{end}}
</tbody>