Ejemplo n.º 1
0
def session():
    print encode_cookie(unicode(current_user.id))
    print dir(current_user)
    response = {'status': 'success', 'session_cookie': ''}
    sessionid = request.cookies['session']
    response['session_cookie'] = sessionid
    return jsonify(response)
Ejemplo n.º 2
0
def session():
    print encode_cookie(unicode(current_user.id))
    print dir(current_user)
    response = {'status':'success', 'session_cookie':''}
    sessionid = request.cookies['session']
    response['session_cookie'] = sessionid
    return jsonify(response)
Ejemplo n.º 3
0
    def test_cookie_encoding(self):
        app = Flask(__name__)
        app.config['SECRET_KEY'] = 'deterministic'

        COOKIE = u'1|7d276051c1eec578ed86f6b8478f7f7d803a7970'

        with app.test_request_context():
            self.assertEqual(COOKIE, encode_cookie(u'1'))
            self.assertEqual(u'1', decode_cookie(COOKIE))
            self.assertIsNone(decode_cookie(u'Foo|BAD_BASH'))
            self.assertIsNone(decode_cookie(u'no bar'))
Ejemplo n.º 4
0
    def test_cookie_encoding(self):
        app = Flask(__name__)
        app.config["SECRET_KEY"] = "deterministic"

        COOKIE = u"1|7d276051c1eec578ed86f6b8478f7f7d803a7970"

        with app.test_request_context():
            self.assertEqual(COOKIE, encode_cookie(u"1"))
            self.assertEqual(u"1", decode_cookie(COOKIE))
            self.assertIsNone(decode_cookie(u"Foo|BAD_BASH"))
            self.assertIsNone(decode_cookie(u"no bar"))
Ejemplo n.º 5
0
    def test_cookie_encoding(self):
        app = Flask(__name__)
        app.config['SECRET_KEY'] = 'deterministic'

        COOKIE = u'1|7d276051c1eec578ed86f6b8478f7f7d803a7970'

        with app.test_request_context():
            self.assertEqual(COOKIE, encode_cookie(u'1'))
            self.assertEqual(u'1', decode_cookie(COOKIE))
            self.assertIsNone(decode_cookie(u'Foo|BAD_BASH'))
            self.assertIsNone(decode_cookie(u'no bar'))
Ejemplo n.º 6
0
def login():
    form = AuthenticationForm(**request.json)
    form.validate()

    user = User.query.filter_by(email=form.email.data).first_or_404()
    if not user.check_password(form.password.data):
        abort(401)

    if login_user(user):
        session_key = encode_cookie(str(session.get('user_id')))
        return jsonify({ 'user': user.serialized, 'session_key': session_key })
    else:
        return error('User account has not been confirmed yet',
                     401, email=user.email)
Ejemplo n.º 7
0
    def test_cookie_encoding(self):
        app = Flask(__name__)
        app.config['SECRET_KEY'] = 'deterministic'

        # COOKIE = u'1|7d276051c1eec578ed86f6b8478f7f7d803a7970'

        # Due to the restriction of 80 chars I have to break up the hash in two
        h1 = u'0e9e6e9855fbe6df7906ec4737578a1d491b38d3fd5246c1561016e189d6516'
        h2 = u'043286501ca43257c938e60aad77acec5ce916b94ca9d00c0bb6f9883ae4b82'
        h3 = u'ae'
        COOKIE = u'1|' + h1 + h2 + h3

        with app.test_request_context():
            self.assertEqual(COOKIE, encode_cookie(u'1'))
            self.assertEqual(u'1', decode_cookie(COOKIE))
            self.assertIsNone(decode_cookie(u'Foo|BAD_BASH'))
            self.assertIsNone(decode_cookie(u'no bar'))
Ejemplo n.º 8
0
def userinfo(user):
    info = dict(
        id=user.id,
        phone='%s****%s' % (user.phone[:3], user.phone[7:]) if user.phone else '',
        email=user.email or '',
        nickname=user.nickname or '',
        avatar=user.avatar.get_link(64, 64),
        avatar_large=user.avatar.link,
        location=user.location or '',
        address=user.address or '',
        resume=user.resume or '',
        debug=user.debug,
        registered=str(user.registered).split('.')[0],
        **user.extend_info
    )
    if request.args.get('token'):
        info['token'] = encode_cookie(unicode(user.get_id()))
    if hasattr(user, 'birthday'):
        info['birthday'] = user.birthday.strftime('%Y-%m-%d') if user.birthday else ''
    if hasattr(user, 'sex'):
        info['sex'] = user.sex
    return info
Ejemplo n.º 9
0
def cookie_encoding(app):
    COOKIE = u"1|7d276051c1eec578ed86f6b8478f7f7d803a7970"
    assert encode_cookie(u"1") == COOKIE
    assert decode_cookie(COOKIE) == u"1"
    assert decode_cookie(u"Foo|BAD_HASH") is None
    assert decode_cookie(u"no bar") is None
Ejemplo n.º 10
0
def cookie_encoding(app):
    COOKIE = u"1|7d276051c1eec578ed86f6b8478f7f7d803a7970"
    assert encode_cookie(u"1") == COOKIE
    assert decode_cookie(COOKIE) == u"1"
    assert decode_cookie(u"Foo|BAD_HASH") is None
    assert decode_cookie(u"no bar") is None