Beispiel #1
0
def login():
    try:
        if current_user.is_authenticated:
            user = User.query.filter(User.id == current_user.id).first()
            return make_response(
                jsonify(to_dict(user, exclude=User.getExclude())))

        form_data = json.loads(request.get_data().decode('utf-8'))

        if ('email' in form_data) and ('password' in form_data):
            user = User.query.filter(
                User.email == form_data['email'],
                User.password == HashValidator.hash(
                    form_data['password'])).first()
            if user is None:
                raise Error(name='Failed login',
                            message='Combinatie email/wachtwoord is onbekend')

            login_user(user)

            return make_response(
                jsonify(to_dict(user, exclude=User.getExclude())))

        else:
            raise Error(
                name='Failed login',
                message='Kan niet inloggen, email en/of wachtwoord ontbreekt')
    except Error as e:
        return make_response(jsonify({e.name: e.message}), 400)
Beispiel #2
0
 def validate_portions(self, key, portions):
     if not NumberValidator.is_int(portions):
         raise Error(name='portions',
                     message='Geen geldig aantal voor porties')
     if portions < 1:
         raise Error(name='portions',
                     message='Het aantal porties kan niet 0 zijn.')
     return portions
Beispiel #3
0
    def validate_dish_id(self, key, dish_id):
        if not NumberValidator.is_int(dish_id):
            raise Error(name='dish_id', message='Not a valid dish id')
        if Dish.query.get(dish_id) is None:
            raise Error(name='dish_id',
                        message='Could not find dish with dish id %r' %
                        dish_id)

        return dish_id
Beispiel #4
0
    def validate_user_id(self, key, user_id):
        if not NumberValidator.is_int(user_id):
            raise Error(name='user_id', message='Not a valid user id')
        if User.query.get(user_id) is None:
            raise Error(name='user_id',
                        message='Could not find user with user id %r' %
                        user_id)

        return user_id
Beispiel #5
0
 def validate_content(self, key, content):
     if len(content) < 10:
         raise Error(
             name='content',
             message=
             'Beoordeling  must be longer than or equal to 10 characters')
     return content
Beispiel #6
0
 def validate_portions_claimed(self, key, portions_claimed):
     if portions_claimed > self.portions:
         raise Error(
             name='portions_claimed',
             message=
             'Het aantal portions_claimed is hoger dan het aantal porties.')
     return portions_claimed
Beispiel #7
0
 def validate_amount_meals(self, key, amount_meals):
     if not NumberValidator.is_int(amount_meals) or amount_meals < 1:
         from app.api.errors.errors import Error
         raise Error(
             name='amount_meals',
             message=
             'Geen juiste waarde, aantal moet groter dan of gelijk zijn aan 1'
         )
     return amount_meals
Beispiel #8
0
def logout():
    try:
        if not current_user.is_authenticated:
            raise Error(name='Kan niet uitloggen',
                        message='Moet ingelogd zijn om uit te loggen')

        logout_user()
        return make_response("", 204)
    except Error as e:
        return make_response(jsonify({e.name: e.message}), 400)
Beispiel #9
0
    def validate_relation_id(self, key, value):
        # save current key/value in foreign_ids
        foreign_ids[key] = value

        # when all foreign keys are assembled we can do our checks
        if len(foreign_ids) is 3:
            # filter foreign_ids to only those with a set value
            filtered_ids = {k: v for k, v in foreign_ids.items() if v != None }

            # raise an error if there is not atleast 1 foreign key
            if len(filtered_ids) <= 0:
                raise Error(name='foreign_id', 
                            message='You need to set one of user_id, cook_id or dish_id')

        return value
Beispiel #10
0
 def validate_rating(self, key, rating):
     if not NumberValidator.between(1, 5, rating):
         raise Error(name='rating',
                     message='Number must be between 1 and 5')
     return rating
Beispiel #11
0
 def validate_available_until(self, key, available_until):
     if available_until < datetime.datetime.utcnow():
         raise Error(name='available_until',
                     message='The datum is in het verleden')
     return available_until
Beispiel #12
0
 def validate_price(self, key, price):
     if not NumberValidator.is_double(price):
         raise Error(name='price', message='Geen juiste prijs(int, float)')
     return price
Beispiel #13
0
 def validate_is_takeout(self, key, is_takeout):
     if not bool(is_takeout):
         raise Error(name='is_takeout',
                     message='Not a boolean for is_takeout.')
     return is_takeout
Beispiel #14
0
 def validate_dinner_time(self, key, dinner_time):
     if dinner_time < datetime.datetime.utcnow():
         raise Error(name='dinner_time',
                     message='The datum is in het verleden')
     return dinner_time