From 2f06faee7523df0f17ccfc4d3c568295734336c2 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 2 Feb 2016 04:19:50 +0100 Subject: manage.py: Replace contrib/create_accounts.py Replace the contrib script with a command in the manage.py. --- manage.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'manage.py') diff --git a/manage.py b/manage.py index bbe654f..d7c7e54 100755 --- a/manage.py +++ b/manage.py @@ -1,9 +1,11 @@ #!/usr/bin/env python from flask import current_app -from flask.ext.script import Manager, Server, Shell, Option +from flask.ext.script import Manager, Server, Shell, Option, prompt_bool from accounts import create_app -from accounts.utils.console import Command, TablePrinter +from accounts.forms import RegisterForm +from accounts.utils.console import Command, ConsoleForm, TablePrinter +from accounts.backend.mail.dummy import DummyBackend as DummyMailBackend class ListServices(Command): @@ -43,6 +45,43 @@ class ListUsers(Command): for user in self._get_users(locked, only_locked)]) +class CreateUser(Command): + """Register a user.""" + name = 'create-user' + + option_list = ( + Option('--ignore-blacklist', action='store_true', + dest='ignore_blacklist', help='Ignore blackisted user names.'), + Option('--print', '-p', action='store_true', dest='print_only', + help='Do not send the activation link via mail, only print it.'), + Option(dest='username', metavar='USERNAME', + help='Username that should be registered.'), + Option(dest='mail', metavar='MAIL', + help='Mail address of the new user.'), + ) + + def run(self, username, mail, ignore_blacklist=False, print_only=False): + form = ConsoleForm(RegisterForm, username=username, mail=mail) + form.csrf_enabled = False + del form.question + + if ignore_blacklist and prompt_bool('Blacklist wirklich ignorieren?'): + current_app.username_blacklist = [] + + if not form.validate(): + form.print_errors() + return + + if print_only: + current_app.mail_backend = DummyMailBackend(current_app) + + current_app.mail_backend.send(mail, 'mail/register.txt', + username=username) + + if not print_only: + print('Mail versandt.') + + def main(): manager = Manager(create_app) manager.add_option('-c', '--config', dest='config', required=False) @@ -55,6 +94,7 @@ def main(): 'shell', Shell()) manager.add_command(ListServices) manager.add_command(ListUsers) + manager.add_command(CreateUser) manager.run() -- cgit v1.2.3-1-g7c22