Exemple #1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument("username",
                            required=True,
                            location='headers',
                            help="Username is required")
        parser.add_argument("password",
                            required=True,
                            location='headers',
                            help="Password is required")
        args = parser.parse_args()

        username = args["username"]
        password = args["password"]

        try:
            user = User.get_by_username(username)
            if not user.check_password(password):
                raise ValueError
        except ValueError:
            return error("Username and/or password is incorrect.", 401)

        sess = Session.new_session(username)
        db.session.add(sess)
        db.session.commit()

        return sess.json(), 200
Exemple #2
0
def test_user_backref(setup):
    username = "******"
    session = Session.new_session(username)
    setup.session.add(session)
    setup.session.commit()
    
    user = User.get_by_username(username)
    ids = [session.id for session in user.sessions]

    assert session.id in ids