예제 #1
0
def reset_db():
    """Recreates and seeds the database."""
    db.drop_all()
    db.create_all()
    db.session.add(User(email="*****@*****.**", password="******"))
    db.session.add(User(email="*****@*****.**", password="******"))
    db.session.commit()
예제 #2
0
def seed_db():
    """Seeds the database."""
    db.session.add(User(email="*****@*****.**", password="******"))
    db.session.add(User(email="*****@*****.**", password="******"))
    db.session.add(
        Wakepark(
            name="Stoke City Wakepark",
            description="The only cable wakepark in Gauteng!",
            lat=-25.952558,
            lng=28.185543,
            instagram_handle="stokecitywake",
            owner_id="google-oauth2|104755831296456998532",
        ))
    db.session.add(
        Wakepark(
            name="Blue Rock",
            description="Wakepark in Cape Town with Unit Parktech features!",
            lat=-34.126774,
            lng=18.901148,
            instagram_handle="blue_rock_waterski",
            owner_id="auth0|5ddb7e53ecc37b0ef0912ab8",
        ))
    db.session.add(
        Wakepark(
            name="Forever Resorts",
            description="Beginner friendly wakepark in Bela-Bela.",
            lat=-24.889612,
            lng=28.290278,
            instagram_handle="forever-resorts",
            owner_id="google-oauth2|104755831296456998532",
        ))
    db.session.commit()
예제 #3
0
    def get(self):
        """Get user status"""
        auth_header = request.headers.get("Authorization")
        res = {"status": False, "message": "Invalid payload."}

        if auth_header:
            try:
                access_token = auth_header.split(" ")

                if len(access_token) > 1:
                    access_token = auth_header.split(" ")[1]
                    resp = User.decode_token(access_token)
                    user = get_user_by_id(resp)
                else:
                    res["message"] = "Invalid header."
                    return res, 401

                if not user:
                    res["message"] = "Invalid token. Please login."
                    return res, 401

                return user.to_json(), 200
            except jwt.ExpiredSignatureError:
                res["message"] = "Signature expired. Please login again."
                return res, 401
            except jwt.InvalidTokenError:
                res["message"] = "Invalid token. Please login again."
                return res, 401
        else:
            res["message"] = "Access token required."
            return res, 403
예제 #4
0
    def post(self):
        """Refresh token"""
        post_data = request.get_json()
        refresh_token = post_data.get("refresh_token")
        res = {"status": False, "message": "Invalid payload."}

        if refresh_token is None:
            return res, 400

        try:
            resp = User.decode_token(refresh_token)
            user = get_user_by_id(resp)

            if not user:
                res["message"] = "Invalid token."
                return res, 400

            access_token = user.encode_token(user.id, "access")
            refresh_token = user.encode_token(user.id, "refresh")

            res = {
                "access_token": access_token.decode(),
                "refresh_token": refresh_token.decode(),
            }

            return res, 200

        except jwt.ExpiredSignatureError:
            res["message"] = "Signature expired. Please login again."
            return res, 401
        except jwt.InvalidTokenError:
            res["message"] = "Invalid token. Please login again."
            return res, 401
예제 #5
0
 def _add_user(email, password):
     user = User(email=email, password=password)
     db.session.add(user)
     db.session.commit()
     return user
예제 #6
0
def seed_db():
    """Seeds the database."""
    db.session.add(User(email="*****@*****.**", password="******"))
    db.session.add(User(email="*****@*****.**", password="******"))
    db.session.commit()
예제 #7
0
def create_user(email, password):
    new_user = User(email=email, password=password)
    db.session.add(new_user)
    db.session.commit()
    return new_user
예제 #8
0
def add_user(email, password):
    # deprectaed in favour of add_user pytest fixture
    user = User(email=email, password=password)
    db.session.add(user)
    db.session.commit()
    return user
def test_decode_token(test_app, test_db, add_user):
    user = add_user("*****@*****.**", "password")
    token = user.encode_token(user.id, "access")
    assert isinstance(token, bytes)
    assert User.decode_token(token) == user.id