Пример #1
0
def create_user():
    """
    Creates a new user with the provided email and password.
    A user with the provided email cannot exist before.
    """
    # The provided data must contain password and email
    data = request.get_json()
    if 'email' not in data or not isinstance(data['email'], str) \
            or 'password' not in data or not isinstance(data['password'], str):
        return jsonify(message="Email or password not provided"), 400

    # Check so that the user doesn't exist.
    if User.user_registered(data['email']):
        return jsonify(message="User already exists"), 400

    # Create the new user and return OK
    user = User.create_user(data['email'], data['password'])
    if user is None:
        abort(500)
    else:
        return jsonify(user.to_json()), 201
Пример #2
0
from application.app import app, db
from application.models import User

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--create',
                        action='store_true',
                        help='Create all tables')
    parser.add_argument('-d',
                        '--drop_all',
                        action='store_true',
                        help='Drop all tables')
    args = parser.parse_args()

    with app.app_context():
        if args.drop_all:
            db.drop_all()
        if args.create:
            db.create_all()

            # add dummy users
            User.create_user('user1', '*****@*****.**')
            User.create_user('user2', '*****@*****.**')