mirror of https://github.com/MedzikUser/go-pingbot
feat(delete): Add password. You must update env (TODO: JWT)
This commit is contained in:
parent
06e6968e31
commit
f8f6c58519
|
@ -2,3 +2,5 @@
|
||||||
MONGODB_URI=mongodb+srv://...
|
MONGODB_URI=mongodb+srv://...
|
||||||
MONGODB_DB=...
|
MONGODB_DB=...
|
||||||
MONGODB_COLLECTION=...
|
MONGODB_COLLECTION=...
|
||||||
|
|
||||||
|
PASSWORD=PrOtEdTeD_pAsSwOrD
|
||||||
|
|
|
@ -11,4 +11,6 @@ var (
|
||||||
Mongo_URI = os.Getenv("MONGODB_URI")
|
Mongo_URI = os.Getenv("MONGODB_URI")
|
||||||
Mongo_DB = os.Getenv("MONGODB_DB")
|
Mongo_DB = os.Getenv("MONGODB_DB")
|
||||||
Mongo_Collection = os.Getenv("MONGODB_COLLECTION")
|
Mongo_Collection = os.Getenv("MONGODB_COLLECTION")
|
||||||
|
|
||||||
|
Password = os.Getenv("PASSWORD")
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,10 +5,24 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"gitlab.com/gaming0skar123/go/pingbot/config"
|
||||||
"gitlab.com/gaming0skar123/go/pingbot/database/mongo"
|
"gitlab.com/gaming0skar123/go/pingbot/database/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Delete(c *gin.Context) {
|
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")
|
url := c.Param("url")
|
||||||
|
|
||||||
d, err := base64.StdEncoding.DecodeString(url)
|
d, err := base64.StdEncoding.DecodeString(url)
|
||||||
|
|
Loading…
Reference in New Issue