Skip to content

Commit 9bea276

Browse files
KN4CK3R6543
andauthored
Add must-change-password cli parameter (#27626)
This PR adds a new `must-change-password` parameter to the `change-password` cli command. We already have the `must-change-password` command but it feels natural to have this integrated into the `change-password` cli command. --------- Co-authored-by: 6543 <[email protected]>
1 parent 360b3fd commit 9bea276

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cmd/admin_user_change_password.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ var microcmdUserChangePassword = &cli.Command{
3232
Value: "",
3333
Usage: "New password to set for user",
3434
},
35+
&cli.BoolFlag{
36+
Name: "must-change-password",
37+
Usage: "User must change password",
38+
},
3539
},
3640
}
3741

@@ -69,7 +73,11 @@ func runChangePassword(c *cli.Context) error {
6973
return err
7074
}
7175

72-
if err = user_model.UpdateUserCols(ctx, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
76+
if c.IsSet("must-change-password") {
77+
user.MustChangePassword = c.Bool("must-change-password")
78+
}
79+
80+
if err = user_model.UpdateUserCols(ctx, user, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
7381
return err
7482
}
7583

docs/content/administration/command-line.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Admin operations:
9595
- Options:
9696
- `--username value`, `-u value`: Username. Required.
9797
- `--password value`, `-p value`: New password. Required.
98+
- `--must-change-password`: If provided, the user is required to choose a new password after the login. Optional.
9899
- Examples:
99100
- `gitea admin user change-password --username myname --password asecurepassword`
100101
- `must-change-password`:

0 commit comments

Comments
 (0)