Add user registration with password hashing and restructure handlers directory
This commit is contained in:
75
internal/web/handlers/admin/adminDash.go
Normal file
75
internal/web/handlers/admin/adminDash.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package handlers_admin
|
||||
|
||||
import (
|
||||
"CatsOfMastodonBotGo/internal"
|
||||
"CatsOfMastodonBotGo/internal/models"
|
||||
requestmodels "CatsOfMastodonBotGo/internal/models/requestModels"
|
||||
"net/http"
|
||||
"CatsOfMastodonBotGo/internal/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AdminDashboardHandler struct {
|
||||
AppContext *internal.AppContext
|
||||
}
|
||||
|
||||
func NewAdminDashboardHandler(appContext *internal.AppContext) *AdminDashboardHandler {
|
||||
return &AdminDashboardHandler{
|
||||
AppContext: appContext,
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) AdminHomePage(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "AdminDashboardHomePage",
|
||||
})
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) ApproveMedia(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "ApproveMedia",
|
||||
})
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "RejectMedia",
|
||||
})
|
||||
}
|
||||
|
||||
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",
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "Login",
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user