Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
feat(delete): Add password. You must update env (TODO: JWT)
Browse files Browse the repository at this point in the history
  • Loading branch information
Medzik authored and Medzik committed Aug 2, 2021
1 parent 06e6968 commit f8f6c58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.schema
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
MONGODB_URI=mongodb+srv://...
MONGODB_DB=...
MONGODB_COLLECTION=...

PASSWORD=PrOtEdTeD_pAsSwOrD
2 changes: 2 additions & 0 deletions config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ var (
Mongo_URI = os.Getenv("MONGODB_URI")
Mongo_DB = os.Getenv("MONGODB_DB")
Mongo_Collection = os.Getenv("MONGODB_COLLECTION")

Password = os.Getenv("PASSWORD")
)
14 changes: 14 additions & 0 deletions website/routes/api/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"gitlab.com/gaming0skar123/go/pingbot/config"
"gitlab.com/gaming0skar123/go/pingbot/database/mongo"
)

func Delete(c *gin.Context) {
const BEARER_SCHEMA = "Password"
authHeader := c.GetHeader("Authorization")
passwordString := authHeader[len(BEARER_SCHEMA)+1:]

if passwordString != config.Password {
c.JSON(http.StatusUnauthorized, json{
"success": false,
"message": "Unauth!",
})

return
}

url := c.Param("url")

d, err := base64.StdEncoding.DecodeString(url)
Expand Down

0 comments on commit f8f6c58

Please sign in to comment.