bump project
This commit is contained in:
28
app/commands.py
Normal file
28
app/commands.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import click
|
||||
from flask import Flask
|
||||
|
||||
from app.extensions import db
|
||||
from app.models import Account, Role
|
||||
|
||||
|
||||
def register_commands(app: Flask) -> None:
|
||||
@app.cli.command("create-admin")
|
||||
@click.option("--username", prompt=True)
|
||||
@click.option("--email", prompt=True)
|
||||
@click.option("--full-name", prompt=True)
|
||||
@click.password_option()
|
||||
def create_admin(username: str, email: str, full_name: str, password: str) -> None:
|
||||
"""Create an initial administrator account."""
|
||||
username = username.strip().lower()
|
||||
email = email.strip().lower()
|
||||
|
||||
if Account.query.filter((Account.username == username) | (Account.email == email)).first():
|
||||
raise click.ClickException("An account with that username or email already exists.")
|
||||
|
||||
account = Account(username=username, email=email, full_name=full_name.strip(), role=Role.ADMIN.value)
|
||||
account.set_password(password)
|
||||
db.session.add(account)
|
||||
db.session.commit()
|
||||
click.echo(f"Created admin account: {username}")
|
||||
Reference in New Issue
Block a user