Handle multiple mail values

This commit is contained in:
Chris Mann 2023-07-27 22:10:04 +02:00
parent b3cc2ecd45
commit c28c25496d
2 changed files with 6 additions and 15 deletions

View file

@ -21,14 +21,16 @@
<div class="form-row">
<div class="form-group col-md-12">
<form method="POST" class="mt-4" enctype="multipart/form-data" action="/user/mail">
{{range $index, $email := .Data.MailValues }}
<form method="POST" class="mt-4" enctype="multipart/form-data" action="/user/mail">
<input type="email" name="email" value="{{$email}}" required>
<input type="submit" name="delete" value="Delete">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="action" value="Delete">
<input type="hidden" name="index" value="{{$index}}">
{{end}}
</form>
{{end}}
<br>
<form method="POST" class="mt-4" enctype="multipart/form-data" action="/user/mail">
<input type="email" name="email" required>

View file

@ -30,7 +30,6 @@ func handleUserMail(w http.ResponseWriter, r *http.Request) {
}
email := r.FormValue("email")
action := r.FormValue("add")
index := r.FormValue("index")
var err error
if action == "Add" {
// Add the new mail value to the entry
@ -42,17 +41,7 @@ func handleUserMail(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("Error adding the email: %v", modifyRequest), http.StatusInternalServerError)
return
}
} else if action == "Delete" && index != "" {
// Delete the specified mail value from the entry
i := strings.Index(index, ":")
if i > 0 {
index = index[:i]
}
i = strings.Index(index, "/")
if i > 0 {
index = index[:i]
}
} else if action == "Delete" {
modifyRequest := ldap.NewModifyRequest(login.Info.DN, nil)
modifyRequest.Delete("mail", []string{email})