40 lines
1.1 KiB
Python
Executable file
40 lines
1.1 KiB
Python
Executable file
#! /usr/bin/env python3
|
|
|
|
import sys
|
|
import os
|
|
import argparse
|
|
|
|
from xenu_nntp.config import Config
|
|
from xenu_nntp.db import Database
|
|
from xenu_nntp.user import User
|
|
|
|
parser = argparse.ArgumentParser(description='Create new account')
|
|
parser.add_argument('--config-file', '-f', type=str, help='Specify a configuration file location')
|
|
parser.add_argument('username', type=str, help='Username of account')
|
|
|
|
args = parser.parse_args()
|
|
|
|
config = Config.load(args.config_file)
|
|
db = Database.from_config(config)
|
|
|
|
user = db.get(User, {'username': args.username})
|
|
|
|
if user is not None:
|
|
print(f"{sys.argv[0]}: user '{args.username}' already exists", file=sys.stderr)
|
|
exit(1)
|
|
|
|
user = User()
|
|
user.active = True
|
|
user.username = args.username
|
|
user.password = '*'
|
|
user.fullname = input('Full name: ')
|
|
user.mail = input('Email address: ')
|
|
|
|
try:
|
|
db.add(user)
|
|
db.commit()
|
|
except Exception as e:
|
|
print(f"Failed to create user '{args.username}': {e}", file=sys.stderr)
|
|
exit(1)
|
|
|
|
print(f"Created user '{args.username}' successfully.")
|