Пример #1
0
def register():
    data = request.get_json()
    user, errors = user_schema.load(data)

    if not is_unique(model=User, key='username', value=data['username']):
        errors['username'] = errors.get('username',
                                        []) + ['Username already taken']

    if not is_unique(model=User, key='email', value=data['email']):
        errors['email'] = errors.get('email', []) + ['email already taken']

    if errors:
        return jsonify(errors), 422

    user.save()

    return jsonify({'message': 'Registration Succesful'}), 201
Пример #2
0
def register():
    data = request.get_json()
    user, errors = user_schema.load(data)
    if not is_unique(model=User, key='username', value=data.get('username')):
        errors['username'] = errors.get('username', []) + [
            'Username already exists, please choose another'
        ]
    if errors:
        return jsonify(errors), 422
    user.save()
    return jsonify({'message': 'Registration Successful'}), 201
Пример #3
0
def create():
    data = request.get_json()
    fact, errors = fact_schema.load(data)
    if not is_unique(model=Fact, key='name', value=data.get('name')):
        errors['name'] = errors.get('name', []) + ['Fact name already taken']
    if errors:
        return jsonify(errors), 422
    fact.year = Year.query.filter_by(year=data['year_number']).first()
    fact.creator = g.current_user
    fact.save()
    return fact_schema.jsonify(fact), 201
def register():
    data = request.get_json()

    user, errors = user_schema.load(data)
    if not is_unique(model=User, key='username', value=data['username']):
        errors['username'] = errors.get('username',
                                        []) + ['Username already taken']

    if not is_unique(model=User, key='email', value=data['email']):
        errors['email'] = errors.get('email', []) + ['Email already taken']

    # if not validate_email(data['email']):
    #     errors['email'] = errors.get('email', []) + ['Email invalid']
    #
    # if not re.match(r"^(?=.*[\d])(?=.*[A-Z])(?=.*[a-z])[\w\d@#$]{6,12}$", data['password']):
    #     errors['password'] = errors.get('password', []) + ['Password must contain at least one uppercase character, one lowercase and one number']

    if errors:
        return jsonify(errors), 422

    user.save()

    return jsonify({'message': 'Registration Successful'}), 201
Пример #5
0
def register():
    try:
        data = request.get_json()
    except:
        return {'message': 'That is not a valid JSON Object'}, 422
    # errors = {}
    user, errors = user_schema.load(data)
    # check if username or email already exists
    for field in ('username', 'email'):
        if not is_unique(model=User, key=field, value=data.get(field)):
            username = field == 'username'
            errors[field] = 'That username is already taken' if username else 'That email already has an account'
    if errors:
        return errors, 422
    user.save()
    return user_schema.jsonify(user), 201
Пример #6
0
def create():
    data = request.get_json()
    recipe, errors = recipe_schema.load(data)
    if not is_unique(model=Recipe, key='name', value=data.get('name')):
        errors['name'] = errors.get('name', []) +['Recipe may already exist - please check against current database or re-name your recipe']
    if errors:
        print(errors)
        return jsonify(errors), 422
    # Adding cuisine
    cuisines = data['cuisines_id']
    for cuisine in cuisines:
        recipe.cuisine.append(Cuisine.query.get(cuisine))
    # Set current user as chef
    recipe.chef = g.current_user

    recipe.save()
    return recipe_schema.jsonify(recipe), 201