Files
gin-gonic-prepack/main.go
🐙PiperYxzzy dbdd4cb650 Adding Live 2fa capacity
* Some requests may be sensitive enough to require a secondary
two-factor authorization on the spot
* Examples: changing password, changing email address, viewing API
tokens etc
* This creates a core handler that can attach to any Auth-able method
which will require a "twofactorcode" query param before processing
2022-05-01 22:34:07 +02:00

53 lines
1.2 KiB
Go

package main
import (
"log"
"net/http"
"github.com/yxzzy-wtf/gin-gonic-prepack/controllers/core"
"github.com/yxzzy-wtf/gin-gonic-prepack/database"
"github.com/yxzzy-wtf/gin-gonic-prepack/models"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func Migrate(g *gorm.DB) {
g.AutoMigrate(&models.User{})
g.AutoMigrate(&models.Admin{})
g.AutoMigrate(&models.TotpUsage{})
}
func main() {
db := database.Init()
Migrate(db)
r := gin.Default()
v1 := r.Group("/v1")
// Ping functionality
v1.GET("/doot", core.Doot())
// Standard user signup, verify, login and forgot/reset pw
v1.POST("/signup", core.UserSignup())
v1.POST("/login", core.UserLogin())
v1.GET("/verify", core.UserVerify())
v1.POST("/forgot", core.UserForgotPassword())
v1.POST("/reset", core.UserResetForgottenPassword())
v1Sec := v1.Group("/sec", core.UserAuth())
v1Sec.GET("/doot", core.Doot())
v1Sec.GET("/2fa-doot", core.LiveTwoFactor(), core.Doot())
// Administrative login
v1.POST("/admin", core.AdminLogin())
v1Admin := v1.Group("/adm", core.AdminAuth())
v1Admin.GET("/doot", core.Doot())
// Start server
if err := http.ListenAndServe(":9091", r); err != nil {
log.Fatal(err)
}
}