Esempio n. 1
0
def remove_languages(_id):
    try:
        _user = user.remove_language(_id)
    except AssertionError as exception_message:
        return make_response(
            jsonify(msg="Error: {}. ".format(exception_message)), 400)
    return user_schema.dump(_user)
Esempio n. 2
0
def login():
    errors = login_schema.validate(request.get_json())
    if errors:
        return {'message': 'Error', 'Error': errors}

    email = request.get_json()['email']
    password = request.get_json()['password']
    rtn = User.query.filter_by(email=email).all()

    if not rtn:
        return {'token': False, 'message': 'Wrong Username'}

    user = user_schema.dump(rtn[0])

    if user and bcrypt.check_password_hash(user['password'], password):

        token = jwt.encode(
            {
                'id': user['id'],
                'exp':
                datetime.datetime.utcnow() + datetime.timedelta(minutes=60)
            },
            current_app.config['SECRET_KEY'],
            algorithm="HS256")
        return jsonify({'token': token, **user_registration_schema.dump(user)})

    return {'token': False, 'message': 'Wrong Password'}
Esempio n. 3
0
def unlike_interest(_id):
    try:
        _user = user.unlike_interest(_id)
    except AssertionError as exception_message:
        return make_response(
            jsonify(msg="Error: {}. ".format(exception_message)), 400)
    return user_schema.dump(_user)
Esempio n. 4
0
    def decorated(*args, **kwargs):
        token = None

        print('mike')

        bearer = request.headers.get('Authorization')
        if not bearer:
            return jsonify({'message': 'Token is missing'}), 401

        token = bearer.split(' ')[1].strip('"')
        try:
            data = jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=["HS256"])
        except Exception as e:
            return jsonify({'message': f'Token is invalid: {e}'}), 401

        rtn = User.query.filter_by(id=data['id']).all()

        if not rtn:
            return {
                'token': False,
                'message': 'User doesnt exist'
            }

        loged_user = user_schema.dump(rtn[0])
        return f(loged_user, *args, **kwargs)