add config option to disable registration
add command to create user
This commit is contained in:
parent
17eabddd70
commit
b8531a0347
10 changed files with 131 additions and 45 deletions
35
realms/modules/auth/commands.py
Normal file
35
realms/modules/auth/commands.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import click
|
||||
from realms.lib.util import random_string
|
||||
from realms.modules.auth.models import User
|
||||
|
||||
|
||||
@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):
|
||||
click.secho("Username %s already exists" % username, fg='red')
|
||||
return
|
||||
|
||||
if User.get_by_email(email):
|
||||
click.secho("Email %s already exists" % email, fg='red')
|
||||
return
|
||||
|
||||
User.create(username, email, password)
|
||||
click.secho("User %s created" % username, fg='green')
|
||||
|
||||
if show_pass:
|
||||
click.secho("Password: %s" % password, fg='yellow')
|
|
@ -2,6 +2,7 @@ from flask_wtf import Form, RecaptchaField
|
|||
from wtforms import StringField, PasswordField, validators
|
||||
from realms import config
|
||||
|
||||
|
||||
class RegistrationForm(Form):
|
||||
username = StringField('Username', [validators.Length(min=4, max=25)])
|
||||
email = StringField('Email Address', [validators.Length(min=6, max=35)])
|
||||
|
|
|
@ -33,6 +33,11 @@ def login():
|
|||
|
||||
@blueprint.route("/register", methods=['GET', 'POST'])
|
||||
def register():
|
||||
|
||||
if not config.REGISTRATION_ENABLED:
|
||||
flash("Registration is disabled")
|
||||
return redirect(url_for(config.ROOT_ENDPOINT))
|
||||
|
||||
form = RegistrationForm()
|
||||
|
||||
if request.method == "POST":
|
||||
|
@ -61,6 +66,7 @@ def register():
|
|||
def settings():
|
||||
return render_template("auth/settings.html")
|
||||
|
||||
|
||||
@blueprint.route("/logout")
|
||||
def logout():
|
||||
User.logout()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue