예제 #1
0
def test_check_login():
    from glashammer.bundles.auth import setup_auth, login
    from glashammer.bundles.sessions import get_session

    called = []

    def check(u, p):
        called.append((u, p))
        return u == p

    def view(req):
        login('a')
        return Response()

    def setup_app(app):
        app.add_setup(setup_auth)
        app.connect_event('password-check', check)
        app.add_url('/', 'a/b', view=view)

    app = make_app(setup_app, 'test_output')
    c = Client(app)
    c.open()

    session = get_session()
    token_key = get_app().conf['auth/token_key']
    assert token_key in session
    assert session[token_key] == 'a'
예제 #2
0
 def session(self):
     """Get current glashammer/securecookie session"""
     # TODO: This has to be refactored! This is in Request, too!
     req = get_request()
     if 'beaker.session' in req.environ:
         return req.environ['beaker.session']
     else:
         return get_session()
예제 #3
0
def login_view(req):
    session = get_session()
    consumer = Consumer(session, None)
    url_back = url_for('openid/login', _external=True)
    if req.method == 'POST':
        url = req.form.get('openid')
        authreq = consumer.begin(url)
        return redirect(authreq.redirectURL(url_back, url_back))
    else:
        res = consumer.complete(req.args, url_back)
        if res.status == SUCCESS:
            identity = req.args.get('openid.identity')
            login(identity)
            return Response('Successfully logged in as: %s' % identity)
        elif res.status == CANCEL:
            return Response('Cancelled')
        else:
            return Response('Nope')
        print res == SUCCESS
예제 #4
0
def logout():
    session = get_session()
    app = get_app()
    del session[app.conf['auth/token_key']]
예제 #5
0
def login(token):
    session = get_session()
    app = get_app()
    session[app.conf['auth/token_key']] = token
예제 #6
0
def get_username():
    session = get_session()
    app = get_app()
    return session.get(app.conf['auth/token_key'])
예제 #7
0
 def wrapped(*args, **kw):
     if get_app().conf['auth/token_key'] in get_session():
         return f(*args, **kw)
     else:
         return redirect(url_for('auth/login'))