diff --git a/accountant/run.py b/accountant/run.py index 54f32de..4383b07 100644 --- a/accountant/run.py +++ b/accountant/run.py @@ -2,8 +2,32 @@ from os import path, getcwd +import click + from . import create_app +from .models import db +from .models.users import User + config_path = path.join(getcwd(), 'config.cfg') # pylint: disable=invalid-name app = create_app(config_path) # pylint: disable=invalid-name + + +# Define commands to handle users. +@app.cli.group() +def user(): + """ User management. """ + pass + + +@user.command() +def add(email, password): + """ Add a new user. """ + user = User() + user.email = email + user.password = User.hash_password(password) + + db.session.add(user) + + click.echo("User '%s' successfully added." % email) diff --git a/accountant/views/users.py b/accountant/views/users.py index d4f7c7d..2056dfb 100644 --- a/accountant/views/users.py +++ b/accountant/views/users.py @@ -15,41 +15,18 @@ along with Accountant. If not, see . """ # vim: set tw=80 ts=4 sw=4 sts=4: -import click - import arrow from functools import wraps -from flask import request, g +from flask import request, g, current_app as app from flask_restplus import Namespace, Resource, fields, marshal_with_field from ..fields import Object from ..models.users import User -from accountant import db - - -# Define commands to handle users. -@app.cli.group() -def user(): - """ User management. """ - pass - - -@user.command() -def add(email, password): - """ Add a new user. """ - user = User() - user.email = email - user.password = User.hash_password(password) - - db.session.add(user) - - click.echo("User '%s' successfully added." % email) - def load_user_from_token(token): return User.verify_auth_token(token)