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
This commit is contained in:
63
main.go
63
main.go
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"whatsapp-bot/db"
|
||||
"whatsapp-bot/handlers"
|
||||
|
||||
@@ -10,39 +10,48 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// 1. Load the .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Println("Warning: No .env file found. Hope you set your vars manually, seki.")
|
||||
}
|
||||
|
||||
godotenv.Load()
|
||||
db.Init()
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
// Load templates so Gin knows where to find your HTML
|
||||
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)
|
||||
|
||||
// Routes
|
||||
r.GET("/webhook", handlers.VerifyWebhook)
|
||||
r.POST("/webhook", handlers.HandleMessage)
|
||||
r.GET("/dashboard", handlers.ShowDashboard)
|
||||
|
||||
r.DELETE("/admin/appointment/:id", handlers.DeleteAppointmentHandler)
|
||||
r.POST("/admin/appointment", handlers.CreateAppointmentHandler)
|
||||
r.PUT("/admin/appointment/:id", handlers.UpdateAppointmentHandler)
|
||||
// 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.POST("/admin/chat", handlers.NewChatHandler) // THE BUTTON HITS THIS
|
||||
r.DELETE("/admin/chat/:id", handlers.DeleteChatHandler) // <--- ADD THIS
|
||||
r.PUT("/admin/chat/:id/rename", handlers.RenameChatHandler) // <--- ADD THIS
|
||||
r.GET("/admin/chat/:id/messages", handlers.GetMessagesHandler)
|
||||
r.POST("/admin/chat/:id/message", handlers.PostMessageHandler)
|
||||
|
||||
// A little something for the root so you don't get a 404 again, seki
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"message": "Bot is running. Go to /dashboard"})
|
||||
})
|
||||
|
||||
r.Run(":9090") // Using your port 9090 from the screenshot
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user