github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/account/pos.go (about) 1 package account 2 3 import ( 4 "context" 5 6 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/middleware" 7 "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx" 8 "github.com/machinefi/w3bstream/pkg/enums" 9 "github.com/machinefi/w3bstream/pkg/errors/status" 10 "github.com/machinefi/w3bstream/pkg/modules/account" 11 ) 12 13 type CreateAccountByUsernameAndPassword struct { 14 httpx.MethodPost `summary:"Create account with username and password"` 15 16 account.CreateAccountByUsernameReq `in:"body"` 17 } 18 19 func (r *CreateAccountByUsernameAndPassword) Path() string { return "/admin" } 20 21 func (r *CreateAccountByUsernameAndPassword) Output(ctx context.Context) (interface{}, error) { 22 ca := middleware.MustCurrentAccountFromContext(ctx) 23 if ca.Role != enums.ACCOUNT_ROLE__ADMIN { 24 return nil, status.NoAdminPermission 25 } 26 return account.CreateAccountByUsername(ctx, &r.CreateAccountByUsernameReq) 27 }