realms-wiki/realms/modules/auth/commands.py

37 lines
836 B
Python
Raw Normal View History

import click
from realms.lib.util import random_string
from realms.modules.auth.models import User
2014-10-22 00:06:27 +03:00
from realms.lib.util import green, red, yellow
@click.group()
def cli():
pass
@cli.command()
@click.argument('username')
@click.argument('email')
@click.option('--password', help='Leave blank for random password')
def create_user(username, email, password):
""" Create a new user
"""
show_pass = not password
if not password:
password = random_string(12)
if User.get_by_username(username):
2014-10-22 00:06:27 +03:00
red("Username %s already exists" % username)
return
if User.get_by_email(email):
2014-10-22 00:06:27 +03:00
red("Email %s already exists" % email)
return
User.create(username, email, password)
2014-10-22 00:06:27 +03:00
green("User %s created" % username)
if show_pass:
2014-10-22 00:06:27 +03:00
yellow("Password: %s" % password)