Account deletion button.

This commit is contained in:
Mihai Parparita 2014-10-12 20:59:16 -07:00
parent 395fe41c7c
commit 7a24dfef8f
5 changed files with 52 additions and 0 deletions

View file

@ -98,6 +98,12 @@ func (account *Account) Put(c appengine.Context) error {
return err
}
func (account *Account) Delete(c appengine.Context) error {
key := datastore.NewKey(c, "Account", "", int64(account.GitHubUserId), nil)
err := datastore.Delete(c, key)
return err
}
func (account *Account) GetDigestEmailAddress(githubClient *github.Client) (string, error) {
if len(account.DigestEmailAddress) > 0 {
return account.DigestEmailAddress, nil

View file

@ -51,6 +51,7 @@ func init() {
router.HandleFunc("/account/settings", settingsHandler).Name("settings").Methods("GET")
router.HandleFunc("/account/settings", saveSettingsHandler).Name("save-settings").Methods("POST")
router.HandleFunc("/account/delete", deleteAccountHandler).Name("delete-account").Methods("POST")
router.HandleFunc("/admin/digest", digestAdminHandler)
http.Handle("/", router)
@ -512,6 +513,24 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, settingsUrl.String(), http.StatusFound)
}
func deleteAccountHandler(w http.ResponseWriter, r *http.Request) {
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
userId := session.Values[sessionConfig.UserIdKey].(int)
c := appengine.NewContext(r)
account, err := getAccount(c, userId)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
account.Delete(c)
session.Options.MaxAge = -1
session.Save(r, w)
indexUrl, _ := router.Get("index").URL()
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
}
func digestAdminHandler(w http.ResponseWriter, r *http.Request) {
userId, err := strconv.Atoi(r.FormValue("user_id"))
if err != nil {

View file

@ -67,3 +67,21 @@ a {
color: #999;
font-style: italic;
}
#delete-account-form {
border-top: solid 1px #ccc;
margin-top: 1em;
padding-top: 1em;
}
input[type="submit"].destructive {
-webkit-appearance: none;
display: inline;
background: transparent;
padding: 0;
border: 0;
font-family: Helvetica, Arial, sans-serif;
font-size: 10pt;
text-decoration: underline;
color: #900;
}

View file

@ -21,3 +21,7 @@ function updateReposContainer() {
reposContainerNode.style.display = "none";
}
}
function confirmDeleteAccount() {
return confirm("Are you sure you want to delete your account?");
}

View file

@ -133,6 +133,11 @@
</form>
<form id="delete-account-form" method="POST" action="{{routeUrl "delete-account"}}" onsubmit="return confirmDeleteAccount()">
If you'd like all data that's stored about your GitHub account removed, you can
<input type="submit" value="Delete Your Account" class="destructive">.
</form>
<script>
updateWeeklyDayContainer();
updateReposContainer();