Exemple #1
0
def auth_token():
    ac = 'Access-Control-'
    headers = {}

    if 'origin' in request.headers:
        headers[ac + 'Allow-Origin'] = request.headers['origin']
        headers[ac + 'Allow-Credentials'] = 'true'
        headers[ac +
                'Expose-Headers'] = 'Location, Content-Type, Content-Length'

        if request.method == 'OPTIONS':
            headers[
                ac +
                'Allow-Headers'] = 'X-Requested-With, Content-Type, Content-Length'
            headers[ac + 'Allow-Methods'] = 'GET, OPTIONS'
            headers[ac + 'Max-Age'] = '86400'

    if g.user:
        c = Consumer.fetch('annotateit')
        payload = {
            'consumerKey': c.key,
            'userId': g.user.username,
            'ttl': c.ttl
        }
        if g.user.is_admin:
            payload['admin'] = True
        token = auth.encode_token(payload, c.secret)
        return Response(token, headers=headers, mimetype='text/plain')
    else:
        return Response('Please go to {0} to log in!'.format(request.host_url),
                        status=401,
                        headers=headers,
                        mimetype='text/plain')
Exemple #2
0
def add_consumer():
    c = Consumer()
    g.user.consumers.append(c)

    db.session.commit()

    return redirect(url_for('.home'))
Exemple #3
0
    def setup(self):
        super(TestMain, self).setup()
        self.cli = self.app.test_client()

        self.user = User('test', '*****@*****.**', 'password')
        self.consumer = Consumer('annotateit')
        self.consumer.secret = 'secret'

        db.session.add(self.user)
        db.session.add(self.consumer)
        db.session.commit()
Exemple #4
0
def auth_token():
    ac = 'Access-Control-'
    headers = {}

    if 'origin' in request.headers:
        headers[ac + 'Allow-Origin']      = request.headers['origin']
        headers[ac + 'Allow-Credentials'] = 'true'
        headers[ac + 'Expose-Headers']    = 'Location, Content-Type, Content-Length'

        if request.method == 'OPTIONS':
            headers[ac + 'Allow-Headers'] = 'X-Requested-With, Content-Type, Content-Length'
            headers[ac + 'Allow-Methods'] = 'GET, OPTIONS'
            headers[ac + 'Max-Age']       = '86400'

    if g.user:
        c = Consumer.fetch('annotateit')
        payload = {'consumerKey': c.key, 'userId': g.user.username, 'ttl': c.ttl}
        if g.user.is_admin:
            payload['admin'] = True
        token = auth.encode_token(payload, c.secret)
        return Response(token, headers=headers, mimetype='text/plain')
    else:
        return Response('Please go to {0} to log in!'.format(request.host_url), status=401, headers=headers, mimetype='text/plain')
 def test_key(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.key, 'foo')
Exemple #6
0
 def consumer(self):
     if not hasattr(self, '_consumer'):
         self._consumer = Consumer.fetch('annotateit')
     return self._consumer
Exemple #7
0
 def consumer(self):
     if not hasattr(self, '_consumer'):
         self._consumer = Consumer.fetch('annotateit') # Allen change to admin
     return self._consumer
        print("Users in DB: " + str(users_count))

        if users_count == 0:
            print("Creating admin user... ")

            u = User(username, email, password)
            u.is_admin = True

            db.session.add(u)
            db.session.commit()

            print("done.\n")

            print("Creating primary consumer... ")

            c = Consumer(ckey)
            c.user_id = u.id
            c.secret = csecret

            db.session.add(c)
            db.session.commit()

            print("done.\n")

            print("Primary consumer key: %s" % c.key)
            print("Primary consumer secret: %s" % c.secret)
        else:
            print("Updating primary consumer... ")

            u = User.query.filter(username='******').first()
            c = Consumer.query.filter(user_id=u.id).first()
        print("Users in DB: " + str(users_count))
        
        if users_count == 0:
            print("Creating admin user... ")

            u = User(username, email, password)
            u.is_admin = True

            db.session.add(u)
            db.session.commit()

            print("done.\n")

            print("Creating primary consumer... ")

            c = Consumer(ckey)
            c.user_id = u.id
            c.secret = csecret

            db.session.add(c)
            db.session.commit()

            print("done.\n")

            print("Primary consumer key: %s" % c.key)
            print("Primary consumer secret: %s" % c.secret)
        else:
            print("Updating primary consumer... ")

            u = User.query.filter(username='******').first()
            c = Consumer.query.filter(user_id=u.id).first()
Exemple #10
0
 def setup(self):
     super(TestConsumer, self).setup()
     c = Consumer('foo')
     db.session.add(c)
     db.session.commit()
Exemple #11
0
 def test_default_ttl(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.ttl, 86400)
Exemple #12
0
 def test_secret(self):
     c = Consumer.fetch('foo')
     assert c.secret, 'Consumer secret should be set!'
Exemple #13
0
 def test_key(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.key, 'foo')
 def test_secret(self):
     c = Consumer.fetch('foo')
     assert c.secret, 'Consumer secret should be set!'
Exemple #15
0
    password = ''
    while not password:
        password = getpass("Admin password: "******"Primary consumer key [annotateit]: ").strip()
    if not ckey:
        ckey = 'annotateit'

    with app.test_request_context():
        print("\nCreating admin user... ", end="")

        u = User(username, email, password)
        u.is_admin = True

        db.session.add(u)
        db.session.commit()

        print("done.")

        print("Creating primary consumer... ", end="")

        c = Consumer(ckey)
        c.user_id = u.id

        db.session.add(c)
        db.session.commit()

        print("done.\n")

        print("Primary consumer secret: %s" % c.secret)
 def test_default_ttl(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.ttl, 86400)
Exemple #17
0
    password = ''
    while not password:
        password = getpass("Admin password: "******"Primary consumer key [annotateit]: ").strip()
    if not ckey:
        ckey = 'annotateit'

    with app.test_request_context():
        print("\nCreating admin user... ", end="")

        u = User(username, email, password)
        u.is_admin = True

        db.session.add(u)
        db.session.commit()

        print("done.")

        print("Creating primary consumer... ", end="")

        c = Consumer(ckey)
        c.user_id = u.id

        db.session.add(c)
        db.session.commit()

        print("done.\n")

        print("Primary consumer secret: %s" % c.secret)