Move user management commands in runner.

This commit is contained in:
Alexis Lahouze 2017-05-13 10:41:03 +02:00
parent 666ef171d8
commit d9da95aaa0
2 changed files with 25 additions and 24 deletions

View File

@ -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)

View File

@ -15,41 +15,18 @@
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
"""
# 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)