Remove user authentication and switch to simple admin password check (It wont have more than one admin user so no need for registeration (I LOVE .Net/C# btw))
This commit is contained in:
@@ -2,10 +2,9 @@ package handlers_admin
|
||||
|
||||
import (
|
||||
"CatsOfMastodonBotGo/internal"
|
||||
"CatsOfMastodonBotGo/internal/models"
|
||||
requestmodels "CatsOfMastodonBotGo/internal/models/requestModels"
|
||||
"net/http"
|
||||
"CatsOfMastodonBotGo/internal/auth"
|
||||
|
||||
requestmodels "CatsOfMastodonBotGo/internal/models/requestModels"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -38,36 +37,6 @@ func (appContext *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) Register(c *gin.Context) {
|
||||
|
||||
var input requestmodels.RegisterInput
|
||||
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
hashedPassword, err := auth.HashPassword(input.Password)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
var user = models.ComUser{
|
||||
Username: input.Username,
|
||||
Password: hashedPassword,
|
||||
}
|
||||
if appContext.AppContext.UserService.CreateUser(user) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"success": false,
|
||||
"error": "failed to create user",
|
||||
})
|
||||
} else {
|
||||
c.JSON(200, gin.H{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
|
||||
var input requestmodels.LoginInput
|
||||
@@ -77,14 +46,10 @@ func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var user = appContext.AppContext.UserService.GetUserByUsername(input.Username)
|
||||
if auth.CheckPasswordHash(input.Password, user.Password) && user.IsVerified { // TODO: Add verification process
|
||||
if input.Password == appContext.AppContext.AdminPassword {
|
||||
c.JSON(200, gin.H{
|
||||
"success": true,
|
||||
})
|
||||
} else {
|
||||
c.JSON(200, gin.H{
|
||||
"success": false,
|
||||
"YouAreOn": "AdminDashboardHomePage",
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user