wip: 周天,继续
This commit is contained in:
47
internal/serve/handler/registry.go
Normal file
47
internal/serve/handler/registry.go
Normal file
@ -0,0 +1,47 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/loveuer/nf"
|
||||
"github.com/loveuer/nf/nft/resp"
|
||||
"gorm.io/gorm"
|
||||
"uauth/internal/store/db"
|
||||
"uauth/internal/tool"
|
||||
"uauth/model"
|
||||
)
|
||||
|
||||
func ClientRegistry(c *nf.Ctx) error {
|
||||
type Req struct {
|
||||
ClientId string `json:"client_id"`
|
||||
Icon string `json:"icon"` // url
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
)
|
||||
|
||||
if err = c.BodyParser(req); err != nil {
|
||||
return resp.Resp400(c, err.Error())
|
||||
}
|
||||
|
||||
Secret := tool.RandomString(32)
|
||||
|
||||
platform := &model.Platform{
|
||||
ClientId: req.ClientId,
|
||||
Icon: req.Icon,
|
||||
Name: req.Name,
|
||||
ClientSecret: Secret,
|
||||
}
|
||||
|
||||
if err = db.Default.Session().Create(platform).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return resp.Resp400(c, err, "当前平台已经存在")
|
||||
}
|
||||
|
||||
return resp.Resp500(c, err)
|
||||
}
|
||||
|
||||
return resp.Resp200(c, platform)
|
||||
}
|
@ -132,6 +132,7 @@ func Run(ctx context.Context) error {
|
||||
|
||||
api := app.Group(opt.Cfg.Svc.Prefix)
|
||||
// 设置路由
|
||||
api.Post("/client/registry", handler.ClientRegistry)
|
||||
api.Get("/login", handler.LoginPage)
|
||||
api.Post("/login", handler.LoginAction)
|
||||
api.Get("/authorize", handler.Authorize)
|
||||
|
Reference in New Issue
Block a user