Switch from cookie to Bearer token auth and add CORS support - Semi finished
This commit is contained in:
@@ -45,10 +45,15 @@ func (appContext *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) GetMedia(c *gin.Context) {
|
||||
media := appContext.AppContext.PostService.GetMedia()
|
||||
c.JSON(http.StatusOK, media)
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
|
||||
var input requestmodels.LoginInput
|
||||
|
||||
|
||||
// Validate data
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -62,17 +67,13 @@ func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.SetCookie("token", token, 3600, "/", "", false, true)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Login successful"})
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Login successful", "token": token})
|
||||
|
||||
} else {
|
||||
c.JSON(401, gin.H{
|
||||
"YouAreOn": "Unauthorized",
|
||||
"error": "wrong password",
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "Login",
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user