mirror of
https://github.com/cuigh/swirl
synced 2025-05-08 13:54:34 +00:00
Add server-side data validation
This commit is contained in:
parent
7ae3a72e00
commit
4ac6aa0151
@ -36,7 +36,7 @@ func registryList(ctx web.Context) error {
|
||||
|
||||
func registryCreate(ctx web.Context) error {
|
||||
registry := &model.Registry{}
|
||||
err := ctx.Bind(registry)
|
||||
err := ctx.Bind(registry, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -52,7 +52,7 @@ func registryDelete(ctx web.Context) error {
|
||||
|
||||
func registryUpdate(ctx web.Context) error {
|
||||
registry := &model.Registry{}
|
||||
err := ctx.Bind(registry)
|
||||
err := ctx.Bind(registry, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func roleNew(ctx web.Context) error {
|
||||
|
||||
func roleCreate(ctx web.Context) error {
|
||||
role := &model.Role{}
|
||||
err := ctx.Bind(role)
|
||||
err := ctx.Bind(role, true)
|
||||
if err == nil {
|
||||
err = biz.Role.Create(role, ctx.User())
|
||||
}
|
||||
@ -99,7 +99,7 @@ func roleEdit(ctx web.Context) error {
|
||||
|
||||
func roleUpdate(ctx web.Context) error {
|
||||
role := &model.Role{}
|
||||
err := ctx.Bind(role)
|
||||
err := ctx.Bind(role, true)
|
||||
if err == nil {
|
||||
role.ID = ctx.P("id")
|
||||
err = biz.Role.Update(role, ctx.User())
|
||||
|
@ -70,7 +70,7 @@ func userNew(ctx web.Context) error {
|
||||
|
||||
func userCreate(ctx web.Context) error {
|
||||
user := &model.User{}
|
||||
err := ctx.Bind(user)
|
||||
err := ctx.Bind(user, true)
|
||||
if err == nil {
|
||||
user.Type = model.UserTypeInternal
|
||||
err = biz.User.Create(user, ctx.User())
|
||||
@ -135,7 +135,7 @@ func userEdit(ctx web.Context) error {
|
||||
|
||||
func userUpdate(ctx web.Context) error {
|
||||
user := &model.User{}
|
||||
err := ctx.Bind(user)
|
||||
err := ctx.Bind(user, true)
|
||||
if err == nil {
|
||||
err = biz.User.Update(user, ctx.User())
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func volumeNew(ctx web.Context) error {
|
||||
|
||||
func volumeCreate(ctx web.Context) error {
|
||||
info := &model.VolumeCreateInfo{}
|
||||
err := ctx.Bind(info)
|
||||
err := ctx.Bind(info, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -10,6 +10,7 @@ import (
|
||||
"github.com/cuigh/auxo/app"
|
||||
"github.com/cuigh/auxo/app/flag"
|
||||
"github.com/cuigh/auxo/config"
|
||||
"github.com/cuigh/auxo/data/valid"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/auxo/net/web/filter"
|
||||
"github.com/cuigh/auxo/net/web/filter/auth"
|
||||
@ -50,6 +51,7 @@ func server() *web.Server {
|
||||
ws := web.Auto()
|
||||
|
||||
// set render
|
||||
ws.Validator = &valid.Validator{Tag: "valid"}
|
||||
ws.Renderer = jet.New().SetDebug(config.GetBool("debug")).
|
||||
AddFunc("time", misc.FormatTime(setting.TimeZone.Offset)).
|
||||
AddFunc("i18n", misc.Message(setting.Language)).
|
||||
|
@ -26,7 +26,7 @@ const (
|
||||
|
||||
type Role struct {
|
||||
ID string `bson:"_id" json:"id,omitempty"`
|
||||
Name string `bson:"name" json:"name,omitempty"`
|
||||
Name string `bson:"name" json:"name,omitempty" valid:"required"`
|
||||
Description string `bson:"desc" json:"desc,omitempty"`
|
||||
Perms []string `bson:"perms" json:"perms,omitempty"`
|
||||
CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty"`
|
||||
@ -35,11 +35,11 @@ type Role struct {
|
||||
|
||||
type User struct {
|
||||
ID string `bson:"_id" json:"id,omitempty"`
|
||||
Name string `bson:"name" json:"name,omitempty"`
|
||||
LoginName string `bson:"login_name" json:"login_name,omitempty"`
|
||||
Name string `bson:"name" json:"name,omitempty" valid:"required"`
|
||||
LoginName string `bson:"login_name" json:"login_name,omitempty" valid:"required"`
|
||||
Password string `bson:"password" json:"password,omitempty"`
|
||||
Salt string `bson:"salt" json:"salt,omitempty"`
|
||||
Email string `bson:"email" json:"email,omitempty"`
|
||||
Email string `bson:"email" json:"email,omitempty" valid:"required"`
|
||||
Admin bool `bson:"admin" json:"admin,omitempty"`
|
||||
Type UserType `bson:"type" json:"type,omitempty"`
|
||||
Status UserStatus `bson:"status" json:"status,omitempty"`
|
||||
|
@ -17,10 +17,10 @@ import (
|
||||
|
||||
type Registry struct {
|
||||
ID string `bson:"_id" json:"id,omitempty"`
|
||||
Name string `bson:"name" json:"name,omitempty"`
|
||||
URL string `bson:"url" json:"url,omitempty"`
|
||||
Username string `bson:"username" json:"username,omitempty"`
|
||||
Password string `bson:"password" json:"password,omitempty"`
|
||||
Name string `bson:"name" json:"name,omitempty" valid:"required"`
|
||||
URL string `bson:"url" json:"url,omitempty" valid:"required,url"`
|
||||
Username string `bson:"username" json:"username,omitempty" valid:"required"`
|
||||
Password string `bson:"password" json:"password,omitempty" valid:"required"`
|
||||
CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
|
||||
}
|
||||
@ -639,7 +639,7 @@ type NetworkCreateInfo struct {
|
||||
}
|
||||
|
||||
type VolumeCreateInfo struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name" valid:"required"`
|
||||
Driver string `json:"driver"`
|
||||
CustomDriver string `json:"custom_driver"`
|
||||
Options Options `json:"options"`
|
||||
|
Loading…
Reference in New Issue
Block a user