diff --git a/app/account.go b/app/account.go index 60bb127..7ebebc7 100644 --- a/app/account.go +++ b/app/account.go @@ -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 diff --git a/app/githop.go b/app/githop.go index 2b8de60..33f12d0 100644 --- a/app/githop.go +++ b/app/githop.go @@ -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 { diff --git a/app/static/main.css b/app/static/main.css index f706995..89f03c4 100644 --- a/app/static/main.css +++ b/app/static/main.css @@ -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; +} diff --git a/app/static/settings.js b/app/static/settings.js index 8111e67..8308211 100644 --- a/app/static/settings.js +++ b/app/static/settings.js @@ -21,3 +21,7 @@ function updateReposContainer() { reposContainerNode.style.display = "none"; } } + +function confirmDeleteAccount() { + return confirm("Are you sure you want to delete your account?"); +} diff --git a/app/templates/settings.html b/app/templates/settings.html index ff83a78..8568f05 100644 --- a/app/templates/settings.html +++ b/app/templates/settings.html @@ -133,6 +133,11 @@ +
+ If you'd like all data that's stored about your GitHub account removed, you can + . +
+