Ejemplo n.º 1
0
def create_user():
    user_creation_request = get_json_from_request('user')
    validation_result, validation_errors = valid_create_user_submission(user_creation_request)
    if not validation_result:
        return jsonify(
            error="Invalid JSON",
            error_details=validation_errors
        ), 400

    user = User(
        email_address=user_creation_request['emailAddress'].lower(),
        mobile_number=user_creation_request['mobileNumber'],
        password=hashpw(user_creation_request['password']),
        active=False,
        created_at=datetime.utcnow(),
        updated_at=datetime.utcnow(),
        logged_in_at=datetime.utcnow(),
        password_changed_at=datetime.utcnow(),
        failed_login_count=0,
        role='admin'
    )

    try:
        db.session.add(user)
        db.session.commit()
        return jsonify(
            users=user.serialize()
        ), 201
    except IntegrityError as e:
        print(e.orig)
        db.session.rollback()
        abort(400, "failed to create user")
Ejemplo n.º 2
0
def test_should_check_password():
    password = "******"
    password_hash = hashpw(password)
    assert checkpw(password, password_hash) is True
Ejemplo n.º 3
0
def test_should_hash_password():
    password = "******"
    assert password != hashpw(password)
Ejemplo n.º 4
0
def test_should_check_invalid_password():
    password = "******"
    password_hash = hashpw(password)
    assert checkpw("not my password", password_hash) is False