Files
whatsapp-bot/main.go
SekiDesu0 e256fcb073 modified: .env
new file:   __debug_bin.exe
	modified:   bot.db
	modified:   db/db.go
	modified:   go.mod
	new file:   handlers/auth.go
	modified:   handlers/dashboard.go
	new file:   handlers/saas.go
	modified:   handlers/webhook.go
	modified:   main.go
	new file:   saas_bot.db
	modified:   services/openrouter.go
	new file:   services/types.go
	modified:   services/whatsapp.go
	new file:   static/style.css
	modified:   templates/dashboard.html
	new file:   templates/landing.html
	new file:   templates/login.html
	new file:   templates/register.html
	deleted:    types/types.go
2026-03-02 00:38:05 -03:00

58 lines
1.2 KiB
Go

package main
import (
"strconv"
"whatsapp-bot/db"
"whatsapp-bot/handlers"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
db.Init()
r := gin.Default()
r.LoadHTMLGlob("templates/*")
r.Static("/static", "./static") // Serve the CSS
// PUBLIC ROUTES
r.GET("/", handlers.ShowLanding)
r.GET("/login", handlers.ShowLogin)
r.POST("/login", handlers.LoginHandler)
r.GET("/register", handlers.ShowRegister)
r.POST("/register", handlers.RegisterHandler)
r.GET("/logout", handlers.LogoutHandler)
r.GET("/webhook", handlers.VerifyWebhook)
r.POST("/webhook", handlers.HandleMessage)
// PRIVATE ROUTES (Middleware)
auth := r.Group("/")
auth.Use(AuthMiddleware())
{
auth.GET("/dashboard", handlers.UserDashboard)
auth.POST("/update-bot", handlers.UpdateBotSettings)
auth.GET("/api/my-appointments", handlers.MyAppointmentsAPI)
auth.POST("/admin/appointment/:id/cancel", handlers.CancelAppointmentHandler)
}
r.Run(":9090")
}
func AuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
cookie, err := c.Cookie("user_id")
if err != nil {
c.Redirect(302, "/login")
c.Abort()
return
}
// Convert cookie to Int
uid, _ := strconv.Atoi(cookie)
c.Set("userID", uid)
c.Next()
}
}