diff --git a/accountant/models/users.py b/accountant/models/users.py index 244cd22..1243892 100644 --- a/accountant/models/users.py +++ b/accountant/models/users.py @@ -15,6 +15,8 @@ along with Accountant. If not, see . """ # vim: set tw=80 ts=4 sw=4 sts=4: +import click + from passlib.hash import sha256_crypt as crypt from itsdangerous import (URLSafeTimedSerializer as Serializer, BadSignature, SignatureExpired) @@ -26,6 +28,25 @@ from flask_login import UserMixin 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) + + class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(200), nullable=False, unique=True, index=True) diff --git a/accountant/views/users.py b/accountant/views/users.py index 495e4f0..8ec9e32 100644 --- a/accountant/views/users.py +++ b/accountant/views/users.py @@ -19,8 +19,6 @@ import arrow from functools import wraps -import click - from flask import request, g from flask_restplus import Resource, marshal_with_field @@ -32,23 +30,6 @@ from ..models.users import User from .models import user_model, token_model, login_model -# 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)