-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathep_adm_notify.go
More file actions
27 lines (22 loc) · 975 Bytes
/
ep_adm_notify.go
File metadata and controls
27 lines (22 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main
import (
"log/slog"
"net/http"
)
func (app *App) handleAdmNotify(w http.ResponseWriter, r *http.Request, aui *UserInfoAdmin) {
app.logRequestStart(r, "handleAdmNotify", slog.String("admin_username", aui.Username))
if r.Method == http.MethodGet {
if err := app.admRenderTemplate(w, r, "notify", nil, slog.String("admin_username", aui.Username)); err != nil {
app.respondHTTPError(r, w, http.StatusInternalServerError, "Internal Server Error\nfailed rendering template", err, slog.String("admin_username", aui.Username))
}
return
}
if r.Method != http.MethodPost {
app.respondHTTPError(r, w, http.StatusMethodNotAllowed, "Method Not Allowed", nil, slog.String("admin_username", aui.Username))
return
}
message := r.FormValue("text")
app.logInfo(r, logMsgAdminNotificationsSend, slog.String("admin_username", aui.Username))
app.wsHub.Broadcast(WSMessage("notify," + message))
http.Redirect(w, r, "/admin/notify", http.StatusSeeOther)
}