feat(delete): Add password. You must update env (TODO: JWT)

This commit is contained in:
Medzik 2021-08-02 20:53:50 +00:00
parent 06e6968e31
commit f8f6c58519
3 changed files with 18 additions and 0 deletions

View File

@ -2,3 +2,5 @@
MONGODB_URI=mongodb+srv://...
MONGODB_DB=...
MONGODB_COLLECTION=...
PASSWORD=PrOtEdTeD_pAsSwOrD

View File

@ -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")
)

View File

@ -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)