Add simple example handler for admin functions
This commit is contained in:
parent
df0644f85b
commit
b0ee388986
5 changed files with 36 additions and 2 deletions
|
|
@ -69,6 +69,7 @@ func Router() chi.Router {
|
|||
r.Method("GET", "/source/{globalid}", auth.NewEnsureAuth(getSource))
|
||||
r.Method("GET", "/stadia", auth.NewEnsureAuth(getStadia))
|
||||
r.Method("GET", "/sudo", authenticatedHandler(getSudo))
|
||||
r.Method("POST", "/sudo/sms", auth.NewEnsureAuth(postSudoSMS))
|
||||
r.Method("GET", "/trap/{globalid}", auth.NewEnsureAuth(getTrap))
|
||||
r.Method("GET", "/text/{destination}", auth.NewEnsureAuth(getTextMessages))
|
||||
r.Method("GET", "/upload", authenticatedHandler(getUploadList))
|
||||
|
|
|
|||
27
sync/sudo.go
27
sync/sudo.go
|
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/gorilla/schema"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type contentSudo struct{}
|
||||
|
|
@ -20,3 +22,28 @@ func getSudo(ctx context.Context, user *models.User) (string, interface{}, *erro
|
|||
content := contentAdminDash{}
|
||||
return "sync/sudo.html", content, nil
|
||||
}
|
||||
|
||||
var decoder = schema.NewDecoder()
|
||||
|
||||
type FormSMS struct {
|
||||
Message string `schema:"smsMessage"`
|
||||
Phone string `schema:"smsPhone"`
|
||||
}
|
||||
|
||||
func postSudoSMS(w http.ResponseWriter, r *http.Request, u *models.User) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
respondError(w, "Failed to parse form", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var sms FormSMS
|
||||
|
||||
err = decoder.Decode(&sms, r.PostForm)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to decode form", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Info().Str("msg", sms.Message).Str("phone", sms.Phone).Msg("Got SMS")
|
||||
http.Redirect(w, r, "/sudo", http.StatusFound)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue