Move user management commands in runner.
This commit is contained in:
parent
666ef171d8
commit
d9da95aaa0
@ -2,8 +2,32 @@
|
|||||||
|
|
||||||
from os import path, getcwd
|
from os import path, getcwd
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
from . import create_app
|
from . import create_app
|
||||||
|
|
||||||
|
from .models import db
|
||||||
|
from .models.users import User
|
||||||
|
|
||||||
|
|
||||||
config_path = path.join(getcwd(), 'config.cfg') # pylint: disable=invalid-name
|
config_path = path.join(getcwd(), 'config.cfg') # pylint: disable=invalid-name
|
||||||
app = create_app(config_path) # 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)
|
||||||
|
@ -15,41 +15,18 @@
|
|||||||
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
|
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||||
import click
|
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
from functools import wraps
|
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 flask_restplus import Namespace, Resource, fields, marshal_with_field
|
||||||
|
|
||||||
from ..fields import Object
|
from ..fields import Object
|
||||||
|
|
||||||
from ..models.users import User
|
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):
|
def load_user_from_token(token):
|
||||||
return User.verify_auth_token(token)
|
return User.verify_auth_token(token)
|
||||||
|
Loading…
Reference in New Issue
Block a user