Beispiel #1
0
def validate_user():
    form = UserForm(params())
    if form.validate():
        user = User.query.filter_by(username=form.username.data).first()
        if user and user.check_password(form.password.data):
            return jsonify(user_view(user))
        else:

            return errors({ "error": "Account doesn't exist." })
    else:
        return errors(form.errors)
Beispiel #2
0
def create_user():
    try:
        form = UserForm(params())
        if form.validate():
            user = User()
            user.generate_token()
            form.populate_obj(user)
            db.session.add(user)
            db.session.commit()
            return jsonify(user_view(user))
        else:
            return errors(form.errors)
    except IntegrityError:
        resp = jsonify({
            'username': "******",
            })
        resp.status_code = 400
        return resp