aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-26 23:08:25 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-26 23:08:25 +0100
commit6bbf08af8f8acc93d6aed721f56d70c8aca75ed4 (patch)
treef53a8448bf0573a903ca1f9488195ad5296d76d9
parent717606a54dee2367cc3aa8c4cee19b0e62c442c5 (diff)
downloadeasybridge-6bbf08af8f8acc93d6aed721f56d70c8aca75ed4.tar.gz
easybridge-6bbf08af8f8acc93d6aed721f56d70c8aca75ed4.zip
Account deletion
-rw-r--r--account.go3
-rw-r--r--templates/delete.html12
-rw-r--r--web.go26
3 files changed, 40 insertions, 1 deletions
diff --git a/account.go b/account.go
index 7c58611..9e18ec1 100644
--- a/account.go
+++ b/account.go
@@ -111,6 +111,9 @@ func RemoveAccount(mxUser string, name string) {
defer accountsLock.Unlock()
if u, ok := registeredAccounts[mxUser]; ok {
+ if acct, ok := u[name]; ok {
+ acct.Conn.Close()
+ }
delete(u, name)
}
}
diff --git a/templates/delete.html b/templates/delete.html
new file mode 100644
index 0000000..9d80380
--- /dev/null
+++ b/templates/delete.html
@@ -0,0 +1,12 @@
+{{define "title"}}Delete account |{{end}}
+
+{{define "body"}}
+
+<h4>Really delete account {{.}}?</h4>
+
+<form method="POST">
+ <input type="submit" class="btn btn-danger" name="delete" value="Yes" />
+ <a href="/" class="btn btn-secondary ml-4" href="/">No, go back</a>
+</form>
+
+{{end}}
diff --git a/web.go b/web.go
index 83d3283..9983855 100644
--- a/web.go
+++ b/web.go
@@ -3,13 +3,13 @@ package main
import (
"crypto/rand"
"html/template"
- "log"
"net/http"
"strconv"
"strings"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
+ log "github.com/sirupsen/logrus"
"golang.org/x/crypto/argon2"
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
@@ -310,4 +310,28 @@ func configForm(w http.ResponseWriter, r *http.Request,
}
func handleDelete(w http.ResponseWriter, r *http.Request) {
+ templateDelete := template.Must(template.ParseFiles("templates/layout.html", "templates/delete.html"))
+
+ login := checkLogin(w, r)
+ if login == nil {
+ return
+ }
+
+ account := mux.Vars(r)["account"]
+
+ if r.Method == "POST" {
+ r.ParseForm()
+ del := strings.Join(r.Form["delete"], "")
+ if del == "Yes" {
+ RemoveAccount(login.MxId, account)
+ db.Where(&DbAccountConfig{
+ MxUserID: login.MxId,
+ Name: account,
+ }).Delete(&DbAccountConfig{})
+ http.Redirect(w, r, "/", http.StatusFound)
+ return
+ }
+ }
+
+ templateDelete.Execute(w, account)
}