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'
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()
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
def logout(): session = get_session() app = get_app() del session[app.conf['auth/token_key']]
def login(token): session = get_session() app = get_app() session[app.conf['auth/token_key']] = token
def get_username(): session = get_session() app = get_app() return session.get(app.conf['auth/token_key'])
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'))