Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2022-09-27 02:50:07 +08:00
commit 7cf10b07d4
44 changed files with 4569 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package user
import (
"log"
"os"
"strings"
"github.com/go-chi/chi"
"gorm.io/gorm"
)
type Env struct {
DB *gorm.DB
CookieString string
}
func UserRoutes(db *gorm.DB) chi.Router {
var env Env
env.DB = db
env.CookieString = os.Getenv("COOKIE_STRING")
if env.CookieString == "" {
env.CookieString = "cookie_string"
}
r := chi.NewRouter()
allowRegistration := os.Getenv("ALLOW_REGISTRATION")
if strings.ToUpper(allowRegistration) == "TRUE" || allowRegistration == "1" {
log.Println("Registration enabled.")
r.Post("/register", env.registerRouteHandler)
}
r.Post("/login", env.loginRouteHandler)
r.Post("/logout", env.logoutRouteHandler)
checkLoggedInUserGroup := r.Group(nil)
checkLoggedInUserGroup.Use(env.CheckUserMiddleware)
checkLoggedInUserGroup.Get("/me", env.meRouteHandler)
checkLoggedInUserGroup.Put("/profile", env.setProfileRouteHandler)
return r
}
func NewUserEnv(db *gorm.DB) *Env {
var env Env
env.DB = db
env.CookieString = os.Getenv("COOKIE_STRING")
if env.CookieString == "" {
env.CookieString = "cooking_string"
}
return &env
}