mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
refactor: refresh webui
This commit is contained in:
parent
59d59dd3ed
commit
4c7e037b76
138 changed files with 2232 additions and 1071 deletions
96
api/certificate/acme_user.go
Normal file
96
api/certificate/acme_user.go
Normal file
|
@ -0,0 +1,96 @@
|
|||
package certificate
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetAcmeUser(c *gin.Context) {
|
||||
u := query.AcmeUser
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
user, err := u.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
func CreateAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).SetValidRules(gin.H{
|
||||
"name": "required",
|
||||
"email": "required,email",
|
||||
"ca_dir": "omitempty",
|
||||
}).BeforeExecuteHook(func(ctx *cosy.Ctx[model.AcmeUser]) {
|
||||
if ctx.Model.CADir == "" {
|
||||
ctx.Model.CADir = settings.ServerSettings.CADir
|
||||
}
|
||||
err := ctx.Model.Register()
|
||||
if err != nil {
|
||||
ctx.AbortWithError(err)
|
||||
return
|
||||
}
|
||||
}).Create()
|
||||
}
|
||||
|
||||
func ModifyAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).SetValidRules(gin.H{
|
||||
"name": "omitempty",
|
||||
"email": "omitempty,email",
|
||||
"ca_dir": "omitempty",
|
||||
}).BeforeExecuteHook(func(ctx *cosy.Ctx[model.AcmeUser]) {
|
||||
if ctx.Model.CADir == "" {
|
||||
ctx.Model.CADir = settings.ServerSettings.CADir
|
||||
}
|
||||
|
||||
if ctx.OriginModel.Email != ctx.Model.Email ||
|
||||
ctx.OriginModel.CADir != ctx.Model.CADir {
|
||||
err := ctx.Model.Register()
|
||||
if err != nil {
|
||||
ctx.AbortWithError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}).Modify()
|
||||
}
|
||||
|
||||
func GetAcmeUserList(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).
|
||||
SetFussy("name", "email").
|
||||
PagingList()
|
||||
}
|
||||
|
||||
func DestroyAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).Destroy()
|
||||
}
|
||||
|
||||
func RecoverAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).Recover()
|
||||
}
|
||||
|
||||
func RegisterAcmeUser(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
u := query.AcmeUser
|
||||
user, err := u.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
err = user.Register()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
_, err = u.Where(u.ID.Eq(id)).Updates(user)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
|
@ -2,8 +2,8 @@ package certificate
|
|||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/api/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
|
@ -2,8 +2,8 @@ package certificate
|
|||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/api/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert/dns"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
|
@ -23,3 +23,13 @@ func InitCertificateRouter(r *gin.RouterGroup) {
|
|||
func InitCertificateWebSocketRouter(r *gin.RouterGroup) {
|
||||
r.GET("domain/:name/cert", IssueCert)
|
||||
}
|
||||
|
||||
func InitAcmeUserRouter(r *gin.RouterGroup) {
|
||||
r.GET("acme_users", GetAcmeUserList)
|
||||
r.GET("acme_user/:id", GetAcmeUser)
|
||||
r.POST("acme_user", CreateAcmeUser)
|
||||
r.POST("acme_user/:id", ModifyAcmeUser)
|
||||
r.POST("acme_user/:id/register", RegisterAcmeUser)
|
||||
r.DELETE("acme_user/:id", DestroyAcmeUser)
|
||||
r.PATCH("acme_user/:id", RecoverAcmeUser)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue