Account deletion
This commit is contained in:
parent
717606a54d
commit
6bbf08af8f
3 changed files with 40 additions and 1 deletions
|
@ -111,6 +111,9 @@ func RemoveAccount(mxUser string, name string) {
|
||||||
defer accountsLock.Unlock()
|
defer accountsLock.Unlock()
|
||||||
|
|
||||||
if u, ok := registeredAccounts[mxUser]; ok {
|
if u, ok := registeredAccounts[mxUser]; ok {
|
||||||
|
if acct, ok := u[name]; ok {
|
||||||
|
acct.Conn.Close()
|
||||||
|
}
|
||||||
delete(u, name)
|
delete(u, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
templates/delete.html
Normal file
12
templates/delete.html
Normal file
|
@ -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}}
|
26
web.go
26
web.go
|
@ -3,13 +3,13 @@ package main
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/argon2"
|
"golang.org/x/crypto/argon2"
|
||||||
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
"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) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue