File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 73
73
Usage : "Length of the random password to be generated" ,
74
74
Value : 12 ,
75
75
},
76
+ cli.BoolFlag {
77
+ Name : "access-token" ,
78
+ Usage : "Generate access token for the user" ,
79
+ },
76
80
},
77
81
}
78
82
@@ -300,18 +304,33 @@ func runCreateUser(c *cli.Context) error {
300
304
changePassword = c .Bool ("must-change-password" )
301
305
}
302
306
303
- if err := models . CreateUser ( & models.User {
307
+ u := & models.User {
304
308
Name : username ,
305
309
Email : c .String ("email" ),
306
310
Passwd : password ,
307
311
IsActive : true ,
308
312
IsAdmin : c .Bool ("admin" ),
309
313
MustChangePassword : changePassword ,
310
314
Theme : setting .UI .DefaultTheme ,
311
- }); err != nil {
315
+ }
316
+
317
+ if err := models .CreateUser (u ); err != nil {
312
318
return fmt .Errorf ("CreateUser: %v" , err )
313
319
}
314
320
321
+ if c .Bool ("access-token" ) {
322
+ t := & models.AccessToken {
323
+ Name : "gitea-admin" ,
324
+ UID : u .ID ,
325
+ }
326
+
327
+ if err := models .NewAccessToken (t ); err != nil {
328
+ return err
329
+ }
330
+
331
+ fmt .Printf ("Access token was successfully created... %s\n " , t .Token )
332
+ }
333
+
315
334
fmt .Printf ("New user '%s' has been successfully created!\n " , username )
316
335
return nil
317
336
}
You can’t perform that action at this time.
0 commit comments