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
1
go.mod
1
go.mod
|
|
@ -47,6 +47,7 @@ require (
|
|||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/gorilla/schema v1.4.1 // indirect
|
||||
github.com/invopop/jsonschema v0.13.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -96,6 +96,8 @@ github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfh
|
|||
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
|
||||
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
|
||||
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
|
||||
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{{ template "sync/layout/authenticated.html" . }}
|
||||
|
||||
{{ define "title" }}Dash{{ end }}
|
||||
{{ define "title" }}Sudo{{ end }}
|
||||
{{ define "extraheader" }}
|
||||
{{ end }}
|
||||
{{ define "content" }}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
<i class="bi bi-chat-dots"></i> SMS Testing
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<form action="/sudo/sms" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="smsPhone" class="form-label"
|
||||
>Recipient Phone Number</label
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
type="tel"
|
||||
class="form-control"
|
||||
id="smsPhone"
|
||||
name="smsPhone"
|
||||
placeholder="+1 (555) 123-4567"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -33,7 +34,9 @@
|
|||
<textarea
|
||||
class="form-control"
|
||||
id="smsMessage"
|
||||
name="smsMessage"
|
||||
rows="3"
|
||||
maxlength="130"
|
||||
placeholder="Enter your SMS message here"
|
||||
></textarea>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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