MCPcopy Create free account
hub / github.com/gogs/gogs / runCreateUser

Function runCreateUser

internal/cmd/admin.go:132–167  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

130)
131
132func runCreateUser(c *cli.Context) error {
133 if !c.IsSet("name") {
134 return errors.New("Username is not specified")
135 } else if !c.IsSet("password") {
136 return errors.New("Password is not specified")
137 } else if !c.IsSet("email") {
138 return errors.New("Email is not specified")
139 }
140
141 err := conf.Init(c.String("config"))
142 if err != nil {
143 return errors.Wrap(err, "init configuration")
144 }
145 conf.InitLogging(true)
146
147 if _, err = database.SetEngine(); err != nil {
148 return errors.Wrap(err, "set engine")
149 }
150
151 user, err := database.Handle.Users().Create(
152 context.Background(),
153 c.String("name"),
154 c.String("email"),
155 database.CreateUserOptions{
156 Password: c.String("password"),
157 Activated: true,
158 Admin: c.Bool("admin"),
159 },
160 )
161 if err != nil {
162 return errors.Wrap(err, "create user")
163 }
164
165 fmt.Printf("New user %q has been successfully created!\n", user.Name)
166 return nil
167}
168
169func adminDashboardOperation(operation func() error, successMessage string) func(*cli.Context) error {
170 return func(c *cli.Context) error {

Callers

nothing calls this directly

Calls 7

InitFunction · 0.92
InitLoggingFunction · 0.92
SetEngineFunction · 0.92
UsersMethod · 0.80
PrintfMethod · 0.80
StringMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected