Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions invokeai/app/util/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
import argparse
import getpass
import json
import os
import sys

_root_help = (
"Path to the InvokeAI root directory. If omitted, the root is resolved in this order: "
"the $INVOKEAI_ROOT environment variable, the active virtual environment's parent directory, "
"or $HOME/invokeai."
)

# ---------------------------------------------------------------------------
# useradd
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -129,13 +136,17 @@ def useradd() -> None:
description="Add a user to the InvokeAI database",
epilog="If no arguments are provided, the script will run in interactive mode.",
)
parser.add_argument("--root", "-r", help=_root_help)
parser.add_argument("--email", "-e", help="User email address")
parser.add_argument("--password", "-p", help="User password")
parser.add_argument("--name", "-n", help="User display name (optional)")
parser.add_argument("--admin", "-a", action="store_true", help="Make user an administrator")

args = parser.parse_args()

if args.root:
os.environ["INVOKEAI_ROOT"] = args.root

if args.email or args.password:
if not args.email or not args.password:
print("❌ Error: Both --email and --password are required when using CLI mode")
Expand Down Expand Up @@ -255,11 +266,15 @@ def userdel() -> None:
description="Delete a user from the InvokeAI database",
epilog="If no arguments are provided, the script will run in interactive mode.",
)
parser.add_argument("--root", "-r", help=_root_help)
parser.add_argument("--email", "-e", help="User email address")
parser.add_argument("--force", "-f", action="store_true", help="Delete without confirmation prompt")

args = parser.parse_args()

if args.root:
os.environ["INVOKEAI_ROOT"] = args.root

if args.email:
success = _delete_user_cli(args.email, args.force)
else:
Expand Down Expand Up @@ -358,6 +373,7 @@ def userlist() -> None:
invoke-userlist --json
""",
)
parser.add_argument("--root", "-r", help=_root_help)
parser.add_argument(
"--json",
action="store_true",
Expand All @@ -366,6 +382,9 @@ def userlist() -> None:

args = parser.parse_args()

if args.root:
os.environ["INVOKEAI_ROOT"] = args.root

success = _list_users_json() if args.json else _list_users_table()
sys.exit(0 if success else 1)

Expand Down Expand Up @@ -532,6 +551,7 @@ def usermod() -> None:
description="Modify a user in the InvokeAI database",
epilog="If no arguments are provided, the script will run in interactive mode.",
)
parser.add_argument("--root", "-r", help=_root_help)
parser.add_argument("--email", "-e", help="User email address")
parser.add_argument("--name", "-n", help="New display name")
parser.add_argument("--password", "-p", help="New password")
Expand All @@ -542,6 +562,9 @@ def usermod() -> None:

args = parser.parse_args()

if args.root:
os.environ["INVOKEAI_ROOT"] = args.root

is_admin = None
if args.admin:
is_admin = True
Expand Down