Skip to content

Commit c2748ea

Browse files
adelowolafriks
authored andcommitted
Add must-change-password flag to cli for creating a user (#4955)
* add support for an admin to force a user to change his/her password from thee cli * use BoolFlag instead * default to true * simplify by removing unnneccessary if/else
1 parent 5a4648c commit c2748ea

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

cmd/admin.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ var (
5959
Value: "custom/conf/app.ini",
6060
Usage: "Custom configuration file path",
6161
},
62+
cli.BoolFlag{
63+
Name: "must-change-password",
64+
Usage: "Force the user to change his/her password after initial login",
65+
},
6266
},
6367
}
6468

@@ -285,12 +289,20 @@ func runCreateUser(c *cli.Context) error {
285289
return err
286290
}
287291

292+
// always default to true
293+
var changePassword = true
294+
295+
if c.IsSet("must-change-password") {
296+
changePassword = c.Bool("must-change-password")
297+
}
298+
288299
if err := models.CreateUser(&models.User{
289-
Name: c.String("name"),
290-
Email: c.String("email"),
291-
Passwd: c.String("password"),
292-
IsActive: true,
293-
IsAdmin: c.Bool("admin"),
300+
Name: c.String("name"),
301+
Email: c.String("email"),
302+
Passwd: c.String("password"),
303+
IsActive: true,
304+
IsAdmin: c.Bool("admin"),
305+
MustChangePassword: changePassword,
294306
}); err != nil {
295307
return fmt.Errorf("CreateUser: %v", err)
296308
}

0 commit comments

Comments
 (0)