Skip to content

Commit

Permalink
Add must-change-password flag to cli for creating a user (#4955)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adelowo authored and lafriks committed Oct 20, 2018
1 parent 5a4648c commit c2748ea
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ var (
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.BoolFlag{
Name: "must-change-password",
Usage: "Force the user to change his/her password after initial login",
},
},
}

Expand Down Expand Up @@ -285,12 +289,20 @@ func runCreateUser(c *cli.Context) error {
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{
Name: c.String("name"),
Email: c.String("email"),
Passwd: c.String("password"),
IsActive: true,
IsAdmin: c.Bool("admin"),
Name: c.String("name"),
Email: c.String("email"),
Passwd: c.String("password"),
IsActive: true,
IsAdmin: c.Bool("admin"),
MustChangePassword: changePassword,
}); err != nil {
return fmt.Errorf("CreateUser: %v", err)
}
Expand Down

0 comments on commit c2748ea

Please sign in to comment.