aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-01-28 02:11:19 +0000
committerterminaldweller <devi@terminaldweller.com>2024-01-28 02:11:19 +0000
commit1c012bdc7526821c45894816a33b9967db508d48 (patch)
tree6fdae276f51c7e6ce2002266fb7e7fe7c6f05f93 /main.go
parentremoved exta uselss git clone line (diff)
downloadsms-webhook-1c012bdc7526821c45894816a33b9967db508d48.tar.gz
sms-webhook-1c012bdc7526821c45894816a33b9967db508d48.zip
added basic http auth
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.go b/main.go
index 52d168d..987a005 100644
--- a/main.go
+++ b/main.go
@@ -28,6 +28,7 @@ const (
type handlerWrapper struct {
irc *girc.Client
config TomlConfig
+ app *pocketbase.PocketBase
}
type SMS struct {
@@ -49,6 +50,20 @@ type TomlConfig struct {
// curl -X 'POST' 'http://127.0.0.1:8090/sms' -H 'content-type: application/json; charset=utf-8' -d $'{"from":"1234567890","text":"Test"}'
func (hw handlerWrapper) postHandler(context echo.Context) error {
+ user, pass, ok := context.Request().BasicAuth()
+ if !ok {
+ return context.JSON(http.StatusUnauthorized, "unauthorized")
+ }
+
+ userRecord, err := hw.app.Dao().FindAuthRecordByUsername("users", user)
+ if err != nil {
+ return context.JSON(http.StatusUnauthorized, "unauthorized")
+ }
+
+ if userRecord.Get("password") != pass {
+ return context.JSON(http.StatusUnauthorized, "unauthorized")
+ }
+
sms := new(SMS)
if err := context.Bind(sms); err != nil {
return context.String(http.StatusBadRequest, "bad request")
@@ -142,7 +157,7 @@ func main() {
app := pocketbase.New()
ircChan := make(chan *girc.Client, 1)
- hw := handlerWrapper{irc: nil, config: appConfig}
+ hw := handlerWrapper{irc: nil, config: appConfig, app: app}
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
go runIRC(appConfig, ircChan)