add basic auth with uuid-based access tokens

This commit is contained in:
wisplite
2025-08-27 02:42:48 -05:00
parent 8263f9c50a
commit 362d61eb48
6 changed files with 123 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package routes
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/wisplite/raster/internal/services"
)
func RegisterUserRoutes(rg *gin.RouterGroup) {
user := rg.Group("/user")
user.POST("/createUser", func(c *gin.Context) {
username := c.PostForm("username")
password := c.PostForm("password")
err := services.CreateUser(username, password)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "User created successfully"})
})
user.POST("/login", func(c *gin.Context) {
username := c.PostForm("username")
password := c.PostForm("password")
accessToken, err := services.Login(username, password)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Login successful", "accessToken": accessToken.Token})
})
}