67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
import click
|
|
|
|
from .auth import check_password as auth_check_password, hash_password
|
|
from .db import (
|
|
add_domain as db_add_domain,
|
|
remove_domain as db_remove_domain,
|
|
reset_or_create_user,
|
|
)
|
|
|
|
|
|
def register_cli(app):
|
|
app.cli.command("reset-user")(reset_user)
|
|
app.cli.command("reset-admin")(reset_admin)
|
|
app.cli.command("make-hash")(make_hash)
|
|
app.cli.command("check-password")(check_password)
|
|
app.cli.command("add-domain")(add_domain)
|
|
app.cli.command("remove-domain")(remove_domain)
|
|
|
|
|
|
@click.argument("email")
|
|
@click.argument("password")
|
|
def reset_user(email, password):
|
|
"""Resets or create a user given by the email"""
|
|
hash = hash_password(password)
|
|
reset_or_create_user(email, hash, False)
|
|
|
|
|
|
@click.argument("email")
|
|
@click.argument("password")
|
|
def reset_admin(email, password):
|
|
"""Resets or create an admin given by the email"""
|
|
hash = hash_password(password)
|
|
reset_or_create_user(email, hash, True)
|
|
|
|
|
|
@click.argument("password")
|
|
def make_hash(password):
|
|
"""Creates a salted hash from the password"""
|
|
print(hash_password(password))
|
|
|
|
|
|
@click.argument("password")
|
|
@click.argument("hash")
|
|
def check_password(password, hash):
|
|
"""Checks if the hash is valid for the password"""
|
|
print(auth_check_password(password, hash))
|
|
|
|
|
|
@click.argument("domain")
|
|
def add_domain(domain):
|
|
"""Checks if the hash is valid for the password"""
|
|
if not domain:
|
|
print("You have to pass a domain")
|
|
return
|
|
db_add_domain(domain)
|
|
print(f"Added {domain}")
|
|
|
|
|
|
@click.argument("domain")
|
|
def remove_domain(domain):
|
|
"""Checks if the hash is valid for the password"""
|
|
if not domain:
|
|
print("You have to pass a domain")
|
|
return
|
|
db_remove_domain(domain)
|
|
print(f"Removed {domain}")
|