2016-08-20 01:48:00 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2014-09-14 06:47:17 +03:00
|
|
|
import click
|
2016-08-20 01:48:00 +03:00
|
|
|
|
2016-08-20 20:37:22 +03:00
|
|
|
from realms import cli_group
|
|
|
|
from realms.lib.util import random_string
|
|
|
|
from realms.lib.util import green, red, yellow
|
2016-08-20 01:48:00 +03:00
|
|
|
from .models import User
|
2014-09-14 06:47:17 +03:00
|
|
|
|
2015-10-14 06:52:30 +03:00
|
|
|
|
2016-07-11 00:47:43 +03:00
|
|
|
@cli_group(short_help="Auth Module")
|
2014-09-14 06:47:17 +03:00
|
|
|
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)
|
2014-09-14 06:47:17 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
if User.get_by_email(email):
|
2014-10-22 00:06:27 +03:00
|
|
|
red("Email %s already exists" % email)
|
2014-09-14 06:47:17 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
User.create(username, email, password)
|
2014-10-22 00:06:27 +03:00
|
|
|
green("User %s created" % username)
|
2014-09-14 06:47:17 +03:00
|
|
|
|
|
|
|
if show_pass:
|
2014-10-22 00:06:27 +03:00
|
|
|
yellow("Password: %s" % password)
|