diff options
author | Lanre Adelowo <yo@lanre.wtf> | 2019-05-04 23:03:10 +0100 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-05-04 23:03:09 +0100 |
commit | e0dde8173f0da6cb3628cadca564a219df082d76 (patch) | |
tree | a7df9db0f45ca3ff7a471244108a08089e7029a1 /cmd/admin.go | |
parent | 410301f0eee6d5cc37d483147bf64526708f0f72 (diff) | |
download | gitea-e0dde8173f0da6cb3628cadca564a219df082d76.tar.gz gitea-e0dde8173f0da6cb3628cadca564a219df082d76.zip |
Generate access token in admin cli (#6847)
* add cli flag for access token while creating a user
Diffstat (limited to 'cmd/admin.go')
-rw-r--r-- | cmd/admin.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/cmd/admin.go b/cmd/admin.go index be21ec0f36..ecb4eb48a6 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -73,6 +73,10 @@ var ( Usage: "Length of the random password to be generated", Value: 12, }, + cli.BoolFlag{ + Name: "access-token", + Usage: "Generate access token for the user", + }, }, } @@ -300,7 +304,7 @@ func runCreateUser(c *cli.Context) error { changePassword = c.Bool("must-change-password") } - if err := models.CreateUser(&models.User{ + u := &models.User{ Name: username, Email: c.String("email"), Passwd: password, @@ -308,10 +312,25 @@ func runCreateUser(c *cli.Context) error { IsAdmin: c.Bool("admin"), MustChangePassword: changePassword, Theme: setting.UI.DefaultTheme, - }); err != nil { + } + + if err := models.CreateUser(u); err != nil { return fmt.Errorf("CreateUser: %v", err) } + if c.Bool("access-token") { + t := &models.AccessToken{ + Name: "gitea-admin", + UID: u.ID, + } + + if err := models.NewAccessToken(t); err != nil { + return err + } + + fmt.Printf("Access token was successfully created... %s\n", t.Token) + } + fmt.Printf("New user '%s' has been successfully created!\n", username) return nil } |