Add validate on delete
alex wennerberg alex@alexwennerberg.com
Sun, 06 Dec 2020 11:00:09 -0800
2 files changed,
13 insertions(+),
6 deletions(-)
M
http.go
→
http.go
@@ -553,13 +553,19 @@
func deleteAccountHandler(w http.ResponseWriter, r *http.Request) { user := newGetAuthUser(r) if r.Method == "POST" { - err := deleteUser(user.Username) - if err != nil { - log.Println(err) - renderDefaultError(w, http.StatusInternalServerError) - return + r.ParseForm() + validate := r.Form.Get("validate-delete") + if validate == user.Username { + err := deleteUser(user.Username) + if err != nil { + log.Println(err) + renderDefaultError(w, http.StatusInternalServerError) + return + } + logoutHandler(w, r) + } else { + http.Redirect(w, r, "/me", http.StatusSeeOther) } - logoutHandler(w, r) } }
M
templates/me.html
→
templates/me.html
@@ -28,6 +28,7 @@ value="Save"
/> </div> </form> +<br> <a href="/reset-password">Reset password</a> <p><a href="/my_site/flounder-archive.zip">🗄️ Download my site archive (.zip)</a></p> <details>