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
This commit is contained in:
parent
5a4648cdd6
commit
c2748ea7fe
1 changed files with 17 additions and 5 deletions
12
cmd/admin.go
12
cmd/admin.go
|
@ -59,6 +59,10 @@ var (
|
||||||
Value: "custom/conf/app.ini",
|
Value: "custom/conf/app.ini",
|
||||||
Usage: "Custom configuration file path",
|
Usage: "Custom configuration file path",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "must-change-password",
|
||||||
|
Usage: "Force the user to change his/her password after initial login",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,12 +289,20 @@ func runCreateUser(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// always default to true
|
||||||
|
var changePassword = true
|
||||||
|
|
||||||
|
if c.IsSet("must-change-password") {
|
||||||
|
changePassword = c.Bool("must-change-password")
|
||||||
|
}
|
||||||
|
|
||||||
if err := models.CreateUser(&models.User{
|
if err := models.CreateUser(&models.User{
|
||||||
Name: c.String("name"),
|
Name: c.String("name"),
|
||||||
Email: c.String("email"),
|
Email: c.String("email"),
|
||||||
Passwd: c.String("password"),
|
Passwd: c.String("password"),
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
IsAdmin: c.Bool("admin"),
|
IsAdmin: c.Bool("admin"),
|
||||||
|
MustChangePassword: changePassword,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("CreateUser: %v", err)
|
return fmt.Errorf("CreateUser: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue