summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deleteacc.go38
-rw-r--r--handler.go2
-rw-r--r--main.go2
-rw-r--r--tpls.go8
-rw-r--r--tpls/reallydelete.tpl11
5 files changed, 57 insertions, 4 deletions
diff --git a/deleteacc.go b/deleteacc.go
new file mode 100644
index 0000000..641d3c9
--- /dev/null
+++ b/deleteacc.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "github.com/gorilla/sessions"
+ "kch42.de/gostuff/mailremind/model"
+ "log"
+ "net/http"
+)
+
+type reallydeleteTpldata struct {
+ OK bool
+}
+
+func deleteask(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+ return &reallydeleteTpldata{user != nil}
+}
+
+func deleteacc(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+ outdata := &msgTpldata{Title: "Delete Account"}
+
+ if user == nil {
+ outdata.Class = "error"
+ outdata.Msg = "You need to be logged in to do that"
+ return outdata
+ }
+
+ if err := user.Delete(); err != nil {
+ log.Printf("Error while deleting account: %s", err)
+ outdata.Class = "error"
+ outdata.Msg = "An error occurred during deletion. Please contact support, if this happens again."
+ return outdata
+ }
+
+ delete(sess.Values, "uid")
+ outdata.Class = "success"
+ outdata.Msg = "Account deleted."
+ return outdata
+}
diff --git a/handler.go b/handler.go
index d710b2a..0dc2033 100644
--- a/handler.go
+++ b/handler.go
@@ -59,7 +59,7 @@ func mkHttpHandler(h Handler, tpl *template.Template) http.HandlerFunc {
}
if err := tpl.Execute(rw, outdata); err != nil {
- log.Printf("Error executing template %s: %s", tpl.Name, err)
+ log.Printf("Error executing template %s: %s", tpl.Name(), err)
}
}
}
diff --git a/main.go b/main.go
index 7698b1e..8b57a3c 100644
--- a/main.go
+++ b/main.go
@@ -81,6 +81,8 @@ func main() {
router.HandleFunc("/login", mkHttpHandler(login, tplLogin))
router.HandleFunc("/logincheck", mkHttpHandler(logincheck, tplMsg))
router.HandleFunc("/logout", mkHttpHandler(logout, tplMsg))
+ router.HandleFunc("/delete-acc/yes", mkHttpHandler(deleteacc, tplMsg))
+ router.HandleFunc("/delete-acc", mkHttpHandler(deleteask, tplReallyDelete))
http.Handle("/", router)
diff --git a/tpls.go b/tpls.go
index 10f4322..eefa25d 100644
--- a/tpls.go
+++ b/tpls.go
@@ -17,9 +17,10 @@ func loadTpl(tplpath, name string) *template.Template {
}
var (
- tplRegister *template.Template
- tplMsg *template.Template
- tplLogin *template.Template
+ tplRegister *template.Template
+ tplMsg *template.Template
+ tplLogin *template.Template
+ tplReallyDelete *template.Template
)
func initTpls() {
@@ -31,6 +32,7 @@ func initTpls() {
tplRegister = loadTpl(tplpath, "register")
tplMsg = loadTpl(tplpath, "msg")
tplLogin = loadTpl(tplpath, "login")
+ tplReallyDelete = loadTpl(tplpath, "reallydelete")
}
type msgTpldata struct {
diff --git a/tpls/reallydelete.tpl b/tpls/reallydelete.tpl
new file mode 100644
index 0000000..82afcf1
--- /dev/null
+++ b/tpls/reallydelete.tpl
@@ -0,0 +1,11 @@
+{{define "title"}}Delete Account{{end}}
+
+{{define "content"}}
+ {{if .OK}}
+ <a href="/delete-acc/yes">Click here if you really want to delete your account</a>
+ {{else}}
+ <div class="error">
+ You need to be logged in to do that
+ </div>
+ {{end}}
+{{end}} \ No newline at end of file